Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@pydantic/logfire-cf-workers": "^0.9.0"
},
"devDependencies": {
"openai": "^4.70.3",
"openai": "^6.6.0",
"wrangler": "^4.27.0"
}
}
2 changes: 1 addition & 1 deletion gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"@google/genai": "^1.15.0",
"@types/mime-types": "^3.0.1",
"groq-sdk": "^0.30.0",
"openai": "^4.104.0"
"openai": "^6.6.0"
}
}
22 changes: 16 additions & 6 deletions gateway/src/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,22 @@ function mapOutputParts(message: ChatCompletion.Choice['message']): MessagePart[
parts.push({ type: 'text', content: message.content })
} else if (message.tool_calls) {
for (const toolCall of message.tool_calls) {
parts.push({
type: 'tool_call',
id: toolCall.id,
name: toolCall.function.name,
arguments: toolCall.function.arguments,
})
if (toolCall.type === 'function') {
parts.push({
type: 'tool_call',
id: toolCall.id,
name: toolCall.function.name,
arguments: toolCall.function.arguments,
})
} else {
// https://platform.openai.com/docs/guides/function-calling#custom-tools
parts.push({
type: 'tool_call',
id: toolCall.id,
name: toolCall.custom.name,
arguments: toolCall.custom.input,
})
}
}
} else {
logfire.warning('unexpected message content', { message })
Expand Down
12 changes: 6 additions & 6 deletions gateway/test/gateway.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ exports[`custom proxyPrefixLength > inference > proxyPrefixLength 1`] = `
},
},
],
"created": 1758119097,
"id": "chatcmpl-CGnNZyR6FU8Xsw5X4N2YdTtaYBuWV",
"created": 1761137036,
"id": "chatcmpl-CTSU0dW3oVCau0NVeg6fCWcUUQj2a",
"model": "gpt-5-2025-08-07",
"object": "chat.completion",
"service_tier": "default",
"system_fingerprint": null,
"usage": {
"completion_tokens": 11,
"completion_tokens": 75,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"reasoning_tokens": 64,
"rejected_prediction_tokens": 0,
},
"prompt_tokens": 23,
Expand All @@ -34,9 +34,9 @@ exports[`custom proxyPrefixLength > inference > proxyPrefixLength 1`] = `
"cached_tokens": 0,
},
"pydantic_ai_gateway": {
"cost_estimate": 0.00013875,
"cost_estimate": 0.00077875,
},
"total_tokens": 34,
"total_tokens": 98,
},
}
`;
Expand Down
18 changes: 9 additions & 9 deletions gateway/test/providers/openai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ describe('openai', () => {
const limitDb = new LimitDbD1(env.limitsDB)
const projectStatus = await limitDb.spendStatus('project')
expect(projectStatus).toEqual([
{ entityId: IDS.projectDefault, limit: 4, scope: 'monthly', scopeInterval: expect.any(Date), spend: 0.00013875 },
{ entityId: IDS.projectDefault, limit: 4, scope: 'monthly', scopeInterval: expect.any(Date), spend: 0.00077875 },
])
const userStatus = await limitDb.spendStatus('user')
expect(userStatus).toEqual([
{ entityId: IDS.userDefault, limit: 3, scope: 'weekly', scopeInterval: expect.any(Date), spend: 0.00013875 },
{ entityId: IDS.userDefault, limit: 3, scope: 'weekly', scopeInterval: expect.any(Date), spend: 0.00077875 },
])
const keyStatus = await limitDb.spendStatus('key')
expect(keyStatus.sort((a, b) => a.limit - b.limit)).toEqual([
{ entityId: IDS.keyHealthy, limit: 1, scope: 'daily', scopeInterval: expect.any(Date), spend: 0.00013875 },
{ entityId: IDS.keyHealthy, limit: 2, scope: 'total', scopeInterval: null, spend: 0.00013875 },
{ entityId: IDS.keyHealthy, limit: 1, scope: 'daily', scopeInterval: expect.any(Date), spend: 0.00077875 },
{ entityId: IDS.keyHealthy, limit: 2, scope: 'total', scopeInterval: null, spend: 0.00077875 },
])
})

Expand Down Expand Up @@ -69,18 +69,18 @@ describe('openai', () => {
expect(completion).toMatchSnapshot('llm')
expect(completion.usage).toMatchInlineSnapshot(`
{
"input_tokens": 1315,
"input_tokens": 2003,
"input_tokens_details": {
"cached_tokens": 0,
},
"output_tokens": 799,
"output_tokens": 1436,
"output_tokens_details": {
"reasoning_tokens": 768,
"reasoning_tokens": 1408,
},
"pydantic_ai_gateway": {
"cost_estimate": 0.00963375,
"cost_estimate": 0.01686375,
},
"total_tokens": 2114,
"total_tokens": 3439,
}
`)
expect(otelBatch, 'otelBatch length not 1').toHaveLength(1)
Expand Down
Loading
Loading