Skip to content

Commit c3d142b

Browse files
committed
completions: handle body with no stream / codebuff_metadata
1 parent dce3f39 commit c3d142b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

web/src/api/v1/chat/completions.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function chatCompletionsPost(params: {
4141

4242
try {
4343
// Parse request body
44-
let body: unknown
44+
let body: {}
4545
try {
4646
body = await req.json()
4747
} catch (error) {
@@ -59,6 +59,9 @@ export async function chatCompletionsPost(params: {
5959
)
6060
}
6161

62+
const bodyStream = 'stream' in body && body.stream
63+
const runId = (body as any)?.codebuff_metadata?.run_id
64+
6265
// Extract and validate API key
6366
const apiKey = extractApiKeyFromHeader(req)
6467
if (!apiKey) {
@@ -101,8 +104,8 @@ export async function chatCompletionsPost(params: {
101104
event: AnalyticsEvent.CHAT_COMPLETIONS_REQUEST,
102105
userId,
103106
properties: {
104-
hasStream: !!(body as any).stream,
105-
hasRunId: !!(body as any).codebuff_metadata?.run_id,
107+
hasStream: !!bodyStream,
108+
hasRunId: !!runId,
106109
},
107110
logger,
108111
})
@@ -191,7 +194,7 @@ export async function chatCompletionsPost(params: {
191194

192195
// Handle streaming vs non-streaming
193196
try {
194-
if ((body as any).stream) {
197+
if (bodyStream) {
195198
// Streaming request
196199
const stream = await handleOpenRouterStream({
197200
body,
@@ -252,7 +255,7 @@ export async function chatCompletionsPost(params: {
252255
properties: {
253256
error: error instanceof Error ? error.message : 'Unknown error',
254257
agentId,
255-
streaming: (body as any).stream,
258+
streaming: bodyStream,
256259
},
257260
logger,
258261
})

0 commit comments

Comments
 (0)