Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/...?q=api&page=52&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=api

Returns an array of strings in format "username" or "username/projectName"

Found 19249 results for "api"(759ms)

myApi1 file match

@steffenUpdated 1 year ago

myApi1 file match

@willosbourneUpdated 1 year ago

myApi1 file match

@riodppUpdated 1 year ago

myApi1 file match

@markngUpdated 1 year ago

myApi1 file match

@sa1LUpdated 1 year ago

myApi1 file match

@maxUpdated 1 year ago

myApi1 file match

@phlUpdated 1 year ago

myApi1 file match

@daveliepmannUpdated 1 year ago

api5001 file match

@matthamlinUpdated 1 year ago

api4001 file match

@matthamlinUpdated 1 year ago

Louai_performance_openai_client.ts29 matches

@jeffvincentUpdated 21 mins ago
1// Lou Fantasy Baseball OpenAI AI Analysis Client
2// Robust OpenAI API integration for fantasy baseball performance analysis
3// Val.town Compatible TypeScript Implementation
4
89
90/**
91 * OpenAI API Configuration Interface
92 */
93export interface OpenAIConfig {
94 apiKey: string;
95 model: string;
96 maxTokens: number;
101
102/**
103 * OpenAI API Error Interface
104 */
105export interface OpenAIError {
106 type: "RATE_LIMIT" | "API_ERROR" | "TIMEOUT" | "PARSE_ERROR" | "AUTH_ERROR" | "UNKNOWN";
107 message: string;
108 statusCode?: number;
134 constructor(config?: Partial<OpenAIConfig>) {
135 this.config = {
136 apiKey: config?.apiKey || process.env.OPENAI_API_KEY || "",
137 model: config?.model || process.env.OPENAI_MODEL || "gpt-4-turbo-preview",
138 maxTokens: config?.maxTokens || 4000,
142 };
143
144 if (!this.config.apiKey) {
145 console.error("❌ OpenAI API key not provided. Set OPENAI_API_KEY environment variable.");
146 }
147
262
263 /**
264 * Execute OpenAI API request with comprehensive retry logic
265 */
266 private async executeWithRetry<T>(operation: () => Promise<T>): Promise<T | null> {
297
298 /**
299 * Make OpenAI API request with proper error handling
300 */
301 private async makeOpenAIRequest(prompt: string, requestType: string): Promise<string | null> {
305 console.log(`🤖 Making OpenAI request: ${requestType}`);
306
307 // Validate API key
308 if (!this.config.apiKey) {
309 throw new Error("OpenAI API key not configured");
310 }
311
333 const timeoutId = setTimeout(() => controller.abort(), this.config.requestTimeout);
334
335 const response = await fetch("https://api.openai.com/v1/chat/completions", {
336 method: "POST",
337 headers: {
338 "Authorization": `Bearer ${this.config.apiKey}`,
339 "Content-Type": "application/json",
340 },
356
357 if (!content) {
358 throw new Error("Empty response from OpenAI API");
359 }
360
716
717 /**
718 * Enforce rate limiting between API requests
719 */
720 private async enforceRateLimit(): Promise<void> {
782 else if (statusCode === 429) type = "RATE_LIMIT";
783 else if (statusCode === 408) type = "TIMEOUT";
784 else if (statusCode >= 500) type = "API_ERROR";
785
786 return {
805 const errors: string[] = [];
806
807 if (!this.config.apiKey) {
808 errors.push("OpenAI API key is required");
809 }
810
828
829 /**
830 * Get current configuration (without API key)
831 */
832 public getConfig(): Omit<OpenAIConfig, "apiKey"> {
833 const { apiKey, ...configWithoutKey } = this.config;
834 return configWithoutKey;
835 }
836
837 /**
838 * Test OpenAI API connection
839 */
840 async testConnection(): Promise<{ success: boolean; error?: string; model?: string }> {
841 try {
842 console.log("🧪 Testing OpenAI API connection...");
843
844 const response = await this.makeOpenAIRequest(
845 "Please respond with a simple JSON object: {\"status\": \"connected\", \"message\": \"API test successful\"}",
846 "connection_test",
847 );
848
849 if (!response) {
850 return { success: false, error: "No response from API" };
851 }
852
853 const parsed = JSON.parse(response);
854 if (parsed.status === "connected") {
855 console.log("✅ OpenAI API connection successful");
856 return { success: true, model: this.config.model };
857 }
859 return { success: false, error: "Unexpected response format" };
860 } catch (error) {
861 console.error("❌ OpenAI API connection test failed:", error);
862 return {
863 success: false,
10 TeamPerformanceStats,
11 WaiverWirePlayer,
12 YahooFantasyAPIClient,
13} from "../daily_lineup_scheduler.tsx";
14import { LouTokenStorage } from "../token_storage.tsx";
apiry
snartapi