[Feature]: opt-in hosted-gateway account controls (served-account header, trusted pin, cross-process seat)

Open
#8,761 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
22/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Read the account-pool selection path first: accountLogLabel in the request log, the active-account/affinity/strategy logic, and the per-process session-affinity snapshot added in #7828. Part 1 (a config-gated x-ocx-served-account response header) is the smallest slice and the only one worth starting from, once a maintainer agrees it fits dev; parts 2 and 3 change the auth surface and the round-robin seating rule and need design sign-off. Done means the flag is off by default and tests cover the header being absent when no pooled account was admitted. Note the thread is one day old with no maintainer reply yet.

Written by the indexing model from the issue text.

Description

account-pool enhancement
Area

Authentication and account pool

What are you trying to accomplish?

I run OpenCodex as a hosted gateway that sits behind a multi-tenant app. The app needs three things the local single-user proxy does not:

  1. Attribution. After a turn, the app needs to know which pooled account served it so it can charge the right tenant. That means an opaque account label, never an email or a token.
  2. Pinning. The app needs to send a request on one specific stored account, for example the tenant's own Claude subscription, and have it refused rather than failed over when that account is spent.
  3. Stable placement across processes. Many gateway processes share no state (serverless environments). Each one must put the same session on the same pooled account, or the prompt cache is rebuilt whenever a turn lands on a different process.
What prevents this today?
  • There is no response header naming the served account. accountLogLabel already exists for the request log, but it is not exposed to the caller.
  • There is no per-request account selector. Selection is process-wide: the active account, affinity, or the strategy.
  • Session affinity is per process, plus the private snapshot added in #7828. That snapshot covers a restart on one machine, but not N processes without a shared home. Under round-robin, an unbound keyed session gets a process-dependent pick.
What should OpenCodex do?

I propose three opt-in pieces. Each would be its own small PR, and each is off by default:

  1. Served-account header. Behind an explicit config flag, responses carry x-ocx-served-account: <accountLogLabel>. That is the same non-PII label the request log already stores, and the header is absent when no pooled account was admitted.
  2. Trusted-caller account pin. Behind a config flag, and only for callers authenticated with the admin or a dedicated token, x-ocx-account-provider and x-ocx-account-id select one stored account. A pinned request still records the refusal or cooldown, but it never fails over to another account. A malformed pin, or a pin from an untrusted caller, is refused with 400. It is never silently ignored.
  3. Cross-process seat (round-robin only). An unbound keyed session takes the rendezvous-hash winner of sha256(key \0 accountId) over the eligible accounts, so every process agrees without shared state. On a 429, the session that hit it moves to its hash runner-up. The process's startup selection does not seat a keyed round-robin session.
Example usage or interface
POST /v1/chat/completions
Authorization: Bearer <trusted gateway token>
x-ocx-account-provider: claude
x-ocx-account-id: <stored account id>
→ 200, x-ocx-served-account: anthropic (ab12cd3)
Alternatives or workarounds

The vadymhimself fork has shipped all three on a hosted gateway since 2026-10. There they are gated by an environment flag and use x-agentradar-* header names:

  • the per-request pin and served-account header;
  • the hash seat (0428964be2, b60e434917, 0c4ffad3e3).

Keeping them fork-only works, but every rebase costs a port.

Additional context

I'm asking whether any of the three fits dev before I write code. Part 1 is the smallest and safest, so if you're open to it, I'd start there. Part 2 changes the auth surface, so I'd expect it to need maintainer-sponsored. Header names and gating are open for discussion.

Checks
  • I searched existing issues and documentation.
  • This request describes a concrete OpenCodex workflow rather than merely naming a desired technology.
  • I removed secrets and personal data.
Dominant language
TypeScript
Stars
16.9k
Forks
1.3k
Avg merge
1d 4h
Merged PRs (30d)
814

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lidge-jun/opencodex

All issues in lidge-jun/opencodex

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.