( body: ChatCompletionRequestBody, modelShortName: string, )
| 124 | } |
| 125 | |
| 126 | function buildOpenAIBody( |
| 127 | body: ChatCompletionRequestBody, |
| 128 | modelShortName: string, |
| 129 | ): Record<string, unknown> { |
| 130 | const openaiBody: Record<string, unknown> = { |
| 131 | ...body, |
| 132 | model: modelShortName, |
| 133 | } |
| 134 | |
| 135 | // Transform max_tokens to max_completion_tokens |
| 136 | openaiBody.max_completion_tokens = |
| 137 | openaiBody.max_completion_tokens ?? openaiBody.max_tokens |
| 138 | delete openaiBody.max_tokens |
| 139 | |
| 140 | // Transform reasoning to reasoning_effort (not supported with function tools) |
| 141 | const hasTools = Array.isArray(openaiBody.tools) && openaiBody.tools.length > 0 |
| 142 | if (openaiBody.reasoning && typeof openaiBody.reasoning === 'object') { |
| 143 | const reasoning = openaiBody.reasoning as { |
| 144 | enabled?: boolean |
| 145 | effort?: 'high' | 'medium' | 'low' |
| 146 | } |
| 147 | if ((reasoning.enabled ?? true) && !hasTools) { |
| 148 | openaiBody.reasoning_effort = reasoning.effort ?? 'medium' |
| 149 | } |
| 150 | } |
| 151 | delete openaiBody.reasoning |
| 152 | |
| 153 | // OpenAI doesn't support reasoning_effort with function tools |
| 154 | if (hasTools) { |
| 155 | delete openaiBody.reasoning_effort |
| 156 | } |
| 157 | |
| 158 | // Remove fields that OpenAI doesn't support |
| 159 | delete openaiBody.stop |
| 160 | delete openaiBody.usage |
| 161 | delete openaiBody.provider |
| 162 | delete openaiBody.transforms |
| 163 | delete openaiBody.codebuff_metadata |
| 164 | |
| 165 | return openaiBody |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Convert credits (integer cents) back to a cost value that will result in the same |
no outgoing calls
no test coverage detected