Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat: add model list endpoint to screenpipe-cloud

Louis Beaumont98ff2186cf44
diff --git a/screenpipe-actions/ai-proxy/src/index.ts b/screenpipe-actions/ai-proxy/src/index.ts
index e8a0aa0f0..32666f2da 100644
--- a/screenpipe-actions/ai-proxy/src/index.ts
+++ b/screenpipe-actions/ai-proxy/src/index.ts
@@ -508,6 +508,62 @@ export default Sentry.withSentry(
}
}
+ if (path === '/v1/models' && request.method === 'GET') {
+ try {
+ // Create instances of all providers
+ const providers = {
+ anthropic: createProvider('claude-3-5-sonnet-latest', env),
+ openai: createProvider('gpt-4', env),
+ gemini: createProvider('gemini-1.5-pro', env),
+ };
+
+ // Fetch models from all providers in parallel
+ const results = await Promise.allSettled([
+ providers.anthropic.listModels(),
+ providers.openai.listModels(),
+ providers.gemini.listModels(),
+ ]);
+
+ // Combine and filter out failed requests
+ const models = results
+ .filter(
+ (result): result is PromiseFulfilledResult<{ id: string; name: string; provider: string }[]> =>
+ result.status === 'fulfilled'
+ )
+ .flatMap((result) => result.value);
+
+ const response = new Response(JSON.stringify({ models }), {
+ headers: {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'GET, HEAD, POST, OPTIONS',
+ 'Access-Control-Allow-Headers': '*',
+ 'Content-Type': 'application/json',
+ },
+ });
+ response.headers.append('Vary', 'Origin');
+ return response;
+ } catch (error) {
+ console.error('Error fetching models:', error);
+ const response = new Response(
+ JSON.stringify({
+ error: 'Failed to fetch models',
+ details: error instanceof Error ? error.message : 'Unknown error',
+ }),
+ {
+ status: 500,
+ headers: {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'GET, HEAD, POST, OPTIONS',
+ 'Access-Control-Allow-Headers': '*',
+ 'Content-Type': 'application/json',
+ },
+ }
+ );
+ response.headers.append('Vary', 'Origin');
+ return response;
+ }
+ }
+
const response = new Response('not found', {
status: 404,
headers: {
@@ -550,6 +606,9 @@ terminal 2
HOST=https://ai-proxy.i-f9f.workers.dev
HOST=http://localhost:8787
TOKEN=foobar (check app settings)
+in
+less "$HOME/Library/Application Support/screenpipe/store.bin"
+
curl $HOST/test
diff --git a/screenpipe-actions/ai-proxy/src/providers/anthropic.ts b/screenpipe-actions/ai-proxy/src/providers/anthropic.ts
index 816408c14..68e106aa4 100644
--- a/screenpipe-actions/ai-proxy/src/providers/anthropic.ts
+++ b/screenpipe-actions/ai-proxy/src/providers/anthropic.ts
@@ -150,4 +150,30 @@ export class AnthropicProvider implements AIProvider {
],
};
}
+
+ async listModels(): Promise<{ id: string; name: string; provider: string }[]> {
+ try {
+ const response = await this.client.models.list();
+ return response.data.map((model) => ({
+ id: model.id,
+ name: model.display_name,
+ provider: 'anthropic',
+ }));
+ } catch (error) {
+ console.error('Failed to fetch Anthropic models:', error);
+ // Fallback to known models if API fails
+ return [
+ {
+ id: 'claude-3-5-sonnet-latest',
+ name: 'Claude 3.5 Sonnet',
+ provider: 'anthropic',
+ },
+ {
+ id: 'claude-3-5-haiku-latest',
+ name: 'Claude 3.5 Haiku',
+ provider: 'anthropic',
+ },
+ ];
+ }
+ }
}
diff --git a/screenpipe-actions/ai-proxy/src/providers/base.ts b/screenpipe-actions/ai-proxy/src/providers/base.ts
index a505512be..76849e3f0 100644
--- a/screenpipe-actions/ai-proxy/src/providers/base.ts
+++ b/screenpipe-actions/ai-proxy/src/providers/base.ts
@@ -9,4 +9,5 @@ export interface AIProvider {
createStreamingCompletion(body: RequestBody): Promise<ReadableStream>;
formatMessages(messages: Message[]): any;
formatResponse(response: any): any;
+ listModels(): Promise<{ id: string; name: string; provider: string }[]>;
}
diff --git a/screenpipe-actions/ai-proxy/src/providers/gemini.ts b/screenpipe-actions/ai-proxy/src/providers/gemini.ts
index f0bdf50db..d4196f98d 100644
--- a/screenpipe-actions/ai-proxy/src/providers/gemini.ts
+++ b/screenpipe-actions/ai-proxy/src/providers/gemini.ts
@@ -120,4 +120,43 @@ export class GeminiProvider implements AIProvider {
],
};
}
+
+ async listModels(): Promise<{ id: string; name: string; provider: string }[]> {
+ try {
+ const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${this.client.apiKey}`);
+
+ if (!response.ok) {
+ throw new Error(`Failed to fetch Gemini models: ${response.statusText}`);
+ }
+
+ const data: { models: any[] } = await response.json();
+ return data.models
+ .filter((model: any) => {
+ // Check if model has generateContent method and is not an embedding model
+ return (
+ model.supportedGenerationMethods?.includes('generateContent') && !model.supportedGenerationMethods?.includes('embedContent')
+ );
+ })
+ .map((model: any) => ({
+ id: model.name.replace('models/', ''),
+ name: model.displayName || model.name.replace('models/', ''),
+ provider: 'google',
+ }));
+ } catch (error) {
+ console.error('Failed to fetch Gemini models:', error);
+ // Updated fallback to only latest models
+ return [
+ {
+ id: 'gemini-1.5-pro',
+ name: 'Gemini 1.5 Pro',
+ provider: 'google',
+ },
+ {
+ id: 'gemini-1.5-flash',
+ name: 'Gemini 1.5 Flash',
+ provider: 'google',
+ },
+ ];
+ }
+ }
}
diff --git a/screenpipe-actions/ai-proxy/src/providers/openai.ts b/screenpipe-actions/ai-proxy/src/providers/openai.ts
index 15daed0ea..fe9cf4d8e 100644
--- a/screenpipe-actions/ai-proxy/src/providers/openai.ts
+++ b/screenpipe-actions/ai-proxy/src/providers/openai.ts
@@ -105,4 +105,32 @@ export class OpenAIProvider implements AIProvider {
],
};
}
+
+ async listModels(): Promise<{ id: string; name: string; provider: string }[]> {
+ try {
+ const response = await this.client.models.list();
+ const sixMonthsAgo = new Date();
+ sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
+
+ return response.data
+ .filter((model) => {
+ // Filter out non-LLM models
+ const isNonLLM =
+ model.id.includes('dall-e') || model.id.includes('whisper') || model.id.includes('tts') || model.id.includes('embedding');
+ if (isNonLLM) return false;
+
+ // Check if model is recent (created within last 6 months)
+ const createdAt = new Date(model.created * 1000); // Convert Unix timestamp to Date
+ return createdAt > sixMonthsAgo;
+ })
+ .map((model) => ({
+ id: model.id,
+ name: model.id,
+ provider: 'openai',
+ }));
+ } catch (error) {
+ console.error('Failed to fetch OpenAI models:', error);
+ return [];
+ }
+ }
}