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