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)
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 || "o4-mini",
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}
360788789/**
790* Enforce rate limiting between API requests
791*/
792private async enforceRateLimit(): Promise<void> {
854else if (statusCode === 429) type = "RATE_LIMIT";
855else if (statusCode === 408) type = "TIMEOUT";
856else if (statusCode >= 500) type = "API_ERROR";
857858return {
877const errors: string[] = [];
878879if (!this.config.apiKey) {
880errors.push("OpenAI API key is required");
881}
882900901/**
902* Get current configuration (without API key)
903*/
904public getConfig(): Omit<OpenAIConfig, "apiKey"> {
905const { apiKey, ...configWithoutKey } = this.config;
906return configWithoutKey;
907}
908909/**
910* Test OpenAI API connection
911*/
912async testConnection(): Promise<{ success: boolean; error?: string; model?: string }> {
913try {
914console.log("🧪 Testing OpenAI API connection...");
915916const response = await this.makeOpenAIRequest(
917"Please respond with a simple JSON object: {\"status\": \"connected\", \"message\": \"API test successful\"}",
918"connection_test",
919);
920921if (!response) {
922return { success: false, error: "No response from API" };
923}
924925const parsed = JSON.parse(response);
926if (parsed.status === "connected") {
927console.log("✅ OpenAI API connection successful");
928return { success: true, model: this.config.model };
929}
931return { success: false, error: "Unexpected response format" };
932} catch (error) {
933console.error("❌ OpenAI API connection test failed:", error);
934return {
935success: false,
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
11href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@200;400;900&display=swap"
12rel="stylesheet"
13>