Skip to content

feat(provider): add data residency header support for OpenAI Enterprise#15844

Open
DusKing1 wants to merge 1 commit intoanomalyco:devfrom
DusKing1:feat/add-residency-for-codex
Open

feat(provider): add data residency header support for OpenAI Enterprise#15844
DusKing1 wants to merge 1 commit intoanomalyco:devfrom
DusKing1:feat/add-residency-for-codex

Conversation

@DusKing1
Copy link

@DusKing1 DusKing1 commented Mar 3, 2026

Issue for this PR

No existing issue — this addresses a gap in OpenAI Enterprise support for non-US regions using Codex OAuth.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds the x-openai-internal-codex-residency HTTP header to OpenAI Codex provider requests in packages/opencode/src/plugin/codex.ts.

Problem: OpenAI Enterprise workspaces with US data residency reject Codex API requests from non-US regions with 401 "Workspace is not authorized in this region". OpenCode's Codex auth plugin shares the identical OAuth flow, client ID, and endpoint as OpenAI's own Codex CLI — but is missing this one header.

Fix: Read enforce_residency from provider options and set x-openai-internal-codex-residency in the chat.headers hook. This mirrors exactly how Codex CLI handles it in codex-rs/core/src/default_client.rs. Users configure it via opencode.json:

{
  "provider": {
    "openai": {
      "options": {
        "enforce_residency": "us"
      }
    }
  }
}

The provider options schema already uses .catchall(z.any()), so no schema changes are needed.

How did you verify your code works?

  • Verified the header is added to outgoing requests when enforce_residency is set in provider config
  • Confirmed the header is NOT added when the option is absent (no impact on non-Enterprise users)
  • Cross-referenced with Codex CLI source to ensure header name and value match exactly

Screenshots / recordings

N/A — backend-only change, no UI impact.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. needs:title labels Mar 3, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Hey! Your PR title feat(plugin/codex): add data residency header support for OpenAI Enterprise doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@DusKing1 DusKing1 changed the title feat(plugin/codex): add data residency header support for OpenAI Enterprise feat(opencode): add data residency header support for OpenAI Enterprise Mar 3, 2026
@github-actions github-actions bot removed needs:title needs:compliance This means the issue will auto-close after 2 hours. labels Mar 3, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@DusKing1
Copy link
Author

DusKing1 commented Mar 3, 2026

I verified this change locally and it works as expected. After configuring enforce_residency for the OpenAI provider, requests consistently include the x-openai-internal-codex-residency header.

@DusKing1 DusKing1 changed the title feat(opencode): add data residency header support for OpenAI Enterprise feat(provider): add data residency header support for OpenAI Enterprise Mar 4, 2026
@GreyElec
Copy link

GreyElec commented Mar 4, 2026

it looks good and looking forward to see this in the official version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants