fix: use max_completion_tokens instead of max_tokens for OpenAI-compatible APIs
Azure OpenAI and newer OpenAI models (o1, o3, o4...) reject `max_tokens` with a 400 error and require `max_completion_tokens` instead. Maps `params.max_tokens` → `max_completion_tokens` in the request body, which is the current standard across OpenAI-compatible providers.
This commit is contained in:
@@ -636,9 +636,13 @@ class OpenAIShimMessages {
|
||||
const body: Record<string, unknown> = {
|
||||
model: request.resolvedModel,
|
||||
messages: openaiMessages,
|
||||
max_tokens: params.max_tokens,
|
||||
stream: params.stream ?? false,
|
||||
}
|
||||
if (params.max_tokens !== undefined) {
|
||||
body.max_completion_tokens = params.max_tokens
|
||||
} else if ((params as Record<string, unknown>).max_completion_tokens !== undefined) {
|
||||
body.max_completion_tokens = (params as Record<string, unknown>).max_completion_tokens
|
||||
}
|
||||
|
||||
if (params.stream) {
|
||||
body.stream_options = { include_usage: true }
|
||||
|
||||
Reference in New Issue
Block a user