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: support json_object in screenpipe-cloud/anthropic non streaming openai sdk

Louis Beaumont26ebf785b291
diff --git a/screenpipe-actions/ai-proxy/src/index.ts b/screenpipe-actions/ai-proxy/src/index.ts
index 3137a2638..fd0e3ba19 100644
--- a/screenpipe-actions/ai-proxy/src/index.ts
+++ b/screenpipe-actions/ai-proxy/src/index.ts
@@ -365,24 +365,24 @@ export default Sentry.withSentry(
throw new Error(`API error: ${JSON.stringify(errorData)}`);
}
- const data = (await apiResponse.json()) as { choices: { message: { content: string } }[] };
-
- if (!data.choices?.length) {
- throw new Error('no completion choices returned from api: ' + JSON.stringify(data, null, 2));
- }
-
- // Normalize Anthropic response to match OpenAI format
- const normalizedResponse = isAnthropicModel
- ? {
- choices: [
- {
- message: {
- content: data.choices[0].message.content,
- },
- },
- ],
- }
- : data;
+ const data: any = await apiResponse.json();
+
+ // Handle both OpenAI-style and Anthropic-style responses
+ const content = isAnthropicModel
+ ? // Anthropic format: either content array or direct message
+ data.content?.[0]?.text || data.choices?.[0]?.message?.content || ''
+ : // OpenAI format
+ data.choices?.[0]?.message?.content || '';
+
+ const normalizedResponse = {
+ choices: [
+ {
+ message: {
+ content: content,
+ },
+ },
+ ],
+ };
generation.end({
completionStartTime: new Date(),