MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / createOpenAIOAuthModel

Function createOpenAIOAuthModel

sdk/src/impl/model-provider.ts:169–192  ·  view source on GitHub ↗

* 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,
)

Source from the content-addressed store, hash-verified

167 * Uses a custom fetch that transforms between Chat Completions and Responses API formats.
168 */
169function 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.

Callers 1

getModelForRequestFunction · 0.85

Calls 3

toOpenAIModelIdFunction · 0.90
extractChatGptAccountIdFunction · 0.90

Tested by

no test coverage detected