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=41&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 19287 results for "api"(3179ms)

myApi1 file match

@thejackobrienUpdated 1 year ago

myApi1 file match

@jothsaUpdated 1 year ago

myApi1 file match

@lanamaysuUpdated 1 year ago

myApi1 file match

@jwshinUpdated 1 year ago

myApi1 file match

@beornUpdated 1 year ago

capitalize1 file match

@parthraghavUpdated 1 year ago

myApi1 file match

@andrewnUpdated 1 year ago

myApi1 file match

@sarUpdated 1 year ago

myApi1 file match

@dantaeyoungUpdated 1 year ago

hiapi1 file match

@dnomadbUpdated 1 year ago

Louai_performance_openai_client.ts29 matches

@jeffvincentUpdated 58 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 || "o4-mini",
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
788
789 /**
790 * Enforce rate limiting between API requests
791 */
792 private async enforceRateLimit(): Promise<void> {
854 else if (statusCode === 429) type = "RATE_LIMIT";
855 else if (statusCode === 408) type = "TIMEOUT";
856 else if (statusCode >= 500) type = "API_ERROR";
857
858 return {
877 const errors: string[] = [];
878
879 if (!this.config.apiKey) {
880 errors.push("OpenAI API key is required");
881 }
882
900
901 /**
902 * Get current configuration (without API key)
903 */
904 public getConfig(): Omit<OpenAIConfig, "apiKey"> {
905 const { apiKey, ...configWithoutKey } = this.config;
906 return configWithoutKey;
907 }
908
909 /**
910 * Test OpenAI API connection
911 */
912 async testConnection(): Promise<{ success: boolean; error?: string; model?: string }> {
913 try {
914 console.log("🧪 Testing OpenAI API connection...");
915
916 const response = await this.makeOpenAIRequest(
917 "Please respond with a simple JSON object: {\"status\": \"connected\", \"message\": \"API test successful\"}",
918 "connection_test",
919 );
920
921 if (!response) {
922 return { success: false, error: "No response from API" };
923 }
924
925 const parsed = JSON.parse(response);
926 if (parsed.status === "connected") {
927 console.log("✅ OpenAI API connection successful");
928 return { success: true, model: this.config.model };
929 }
931 return { success: false, error: "Unexpected response format" };
932 } catch (error) {
933 console.error("❌ OpenAI API connection test failed:", error);
934 return {
935 success: false,

basic-html-starterindex.html2 matches

@ivobgUpdated 1 hour ago
6 <meta http-equiv="X-UA-Compatible" content="IE=edge">
7 <meta name="viewport" content="width=device-width, initial-scale=1">
8 <link rel="preconnect" href="https://fonts.googleapis.com">
9 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10 <link
11 href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@200;400;900&display=swap"
12 rel="stylesheet"
13 >
apiry
snartapi