{"record":{"id":"15e5c49ba8d864d4","repo":"vercel/ai","slug":"ai-gateway-auth-was-selected-but-ai-gateway-base-u","errorCode":null,"errorMessage":"AI Gateway auth was selected but AI_GATEWAY_BASE_URL is missing from the Codex bridge environment.","messagePattern":"AI Gateway auth was selected but AI_GATEWAY_BASE_URL is missing from the Codex bridge environment\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/harness-codex/src/bridge/index.ts","lineNumber":139,"sourceCode":"      'utf8',\n    );\n  }\n\n  const codexConfig: Record<string, unknown> = {\n    ...start.codexConfig,\n    developer_instructions: [\n      start.instructions,\n      'Only respond with your `final` message once you have fully addressed the user request.',\n    ]\n      .filter((instruction): instruction is string => Boolean(instruction))\n      .join('\\n\\n'),\n    model_reasoning_summary: 'detailed',\n  };\n\n  const gatewayBaseUrl = procEnv.AI_GATEWAY_BASE_URL;\n  const hasGatewayAuth = Boolean(procEnv.AI_GATEWAY_API_KEY || gatewayBaseUrl);\n  if (hasGatewayAuth && !gatewayBaseUrl) {\n    throw new Error(\n      'AI Gateway auth was selected but AI_GATEWAY_BASE_URL is missing from the Codex bridge environment.',\n    );\n  }\n  const apiBaseUrl = hasGatewayAuth ? gatewayBaseUrl : procEnv.OPENAI_BASE_URL;\n  const codexModel =\n    start.model && hasGatewayAuth && !start.model.includes('/')\n      ? `openai/${start.model}`\n      : start.model;\n  /*\n   * AI Gateway only returns populated reasoning summaries for its\n   * creator-qualified model IDs. Codex treats qualified IDs as custom model\n   * metadata, so its reasoning-summary capability must also be forced on for\n   * the OpenAI Gateway route.\n   */\n  if (hasGatewayAuth && codexModel?.startsWith('openai/')) {\n    codexConfig.model_supports_reasoning_summaries = true;\n  }\n  if (apiBaseUrl) {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness-codex/src/bridge/index.ts#L121-L157","documentation":"The Codex bridge resolves AI Gateway credentials from its process environment. If AI_GATEWAY_API_KEY or AI_GATEWAY_BASE_URL is set (gateway auth selected) but AI_GATEWAY_BASE_URL is absent, it cannot build the gateway API base URL and throws. Gateway auth requires the base URL to configure the Codex process endpoint.","triggerScenarios":"Starting a codex turn with procEnv containing AI_GATEWAY_API_KEY set but AI_GATEWAY_BASE_URL unset; hasGatewayAuth becomes true via the API key while gatewayBaseUrl is undefined.","commonSituations":"Setting only the gateway API key in the environment that spawns the bridge, while AI_GATEWAY_BASE_URL lives in a different env (shell vs .env vs CI secret); typo'd or missing base-url variable in CI.","solutions":["Set AI_GATEWAY_BASE_URL in the environment passed to the Codex bridge process.","If you do not intend gateway auth, remove AI_GATEWAY_API_KEY so it falls back to OPENAI_BASE_URL.","Verify both AI_GATEWAY_* variables are exported in the same environment that spawns the bridge."],"exampleFix":"// before\nAI_GATEWAY_API_KEY=gw_...   # AI_GATEWAY_BASE_URL missing\n// after\nAI_GATEWAY_API_KEY=gw_...\nAI_GATEWAY_BASE_URL=https://ai-gateway.example.com/v1","handlingStrategy":"validation","validationCode":"const env = process.env;\nif ((env.AI_GATEWAY_API_KEY || env.AI_GATEWAY_BASE_URL) && !env.AI_GATEWAY_BASE_URL) {\n  throw new Error('AI_GATEWAY_BASE_URL is required when using AI Gateway auth');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await codex.start(startOpts);\n} catch (e) {\n  if (/AI_GATEWAY_BASE_URL is missing/.test(String(e?.message))) {\n    // inject AI_GATEWAY_BASE_URL into the bridge env and retry\n  } else throw e;\n}","preventionTips":["Set AI_GATEWAY_API_KEY and AI_GATEWAY_BASE_URL together","Verify env vars in CI before spawning the bridge","Or unset AI_GATEWAY_API_KEY to use plain OPENAI_BASE_URL auth"],"tags":["harness-codex","environment","ai-gateway","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}