* Create an OpenAI model that routes through the ChatGPT backend API (Codex endpoint). * Uses a custom fetch that transforms between Chat Completions and Responses API formats.
( model: string, oauthToken: string, )
| 167 | * Uses a custom fetch that transforms between Chat Completions and Responses API formats. |
| 168 | */ |
| 169 | function createOpenAIOAuthModel( |
| 170 | model: string, |
| 171 | oauthToken: string, |
| 172 | ): LanguageModel { |
| 173 | const openAIModelId = toOpenAIModelId(model) |
| 174 | const accountId = extractChatGptAccountId(oauthToken) |
| 175 | |
| 176 | return new OpenAICompatibleChatLanguageModel(openAIModelId, { |
| 177 | provider: 'openai', |
| 178 | url: () => `${CHATGPT_BACKEND_BASE_URL}/codex/responses`, |
| 179 | headers: () => ({ |
| 180 | Authorization: `Bearer ${oauthToken}`, |
| 181 | 'Content-Type': 'application/json', |
| 182 | 'OpenAI-Beta': 'responses=experimental', |
| 183 | originator: 'codex_cli_rs', |
| 184 | accept: 'text/event-stream', |
| 185 | 'user-agent': `ai-sdk/openai-compatible/${VERSION}/codebuff-chatgpt-oauth`, |
| 186 | ...(accountId ? { 'chatgpt-account-id': accountId } : {}), |
| 187 | }), |
| 188 | fetch: createChatGptBackendFetch(), |
| 189 | supportsStructuredOutputs: true, |
| 190 | includeUsage: undefined, |
| 191 | }) |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Create a model that routes through the Codebuff backend. |
no test coverage detected