Skip to content

feat(chat): support x-connection-id account pinning - #4718

Open
nhan14t1 wants to merge 5 commits into
decolua:masterfrom
nhan14t1:feat/chat-connection-pinning
Open

nhan14t1 wants to merge 5 commits into
decolua:masterfrom
nhan14t1:feat/chat-connection-pinning

Conversation

@nhan14t1

Copy link
Copy Markdown

Summary

Adds x-connection-id account pinning to the chat endpoints, mirroring the opt-in already supported by the image/video endpoints.

Motivation

For providers with multiple connected accounts (Antigravity, Codex, ...), account selection is global (fill-first / round-robin). There is no way to prefer a specific account per request — e.g. multi-agent setups where each agent should burn its own account first and only fall back to the shared pool when it is exhausted (quota, rate limit, error).

What changed

  • src/sse/handlers/chat.js — read x-connection-id in handleSingleModelChat and pass it as preferredConnectionId to getProviderCredentials. The pinning + fallback logic already exists in auth.js; this just wires the header through, so single-model, combo, fusion and capacity-adapter paths honor it (6 lines).
  • Dashboard — each connection row shows a copyable connection-id chip (tooltip explains the header), and the Connections section carries a one-line pinning tip, so the feature is discoverable.
  • Docs — new "Account Pinning per Request" section in features/smart-routing.md, incl. a Claude Code example (ANTHROPIC_CUSTOM_HEADERS in ~/.claude/settings.json env block); "Pin a specific account (optional)" in integration/claude-code.md.

Behavior

  • The pinned account is tried first; if unavailable (rate-limited, out of quota, erroring) the request falls back to the provider's other accounts, exactly like unpinned traffic.
  • Absent / unknown / inactive ids are ignored — zero behavior change without the header.

Testing

  • Valid id: log shows pinned to <id> (<email>), request runs on that account, 200 OK.
  • Unknown id: ignored, normal strategy, 200 OK.
  • No header: unchanged behavior.
  • E2E: Claude Code (VS Code extension) with ANTHROPIC_CUSTOM_HEADERS: "x-connection-id: <id>" — full agentic session (33 tools, multi-turn) pinned to the expected account, claude→antigravity translation intact.

<screenshot of the provider page with the id chip + tip>

Mirror the existing image/video opt-in: read x-connection-id in the chat
single-model path and pass it to getProviderCredentials as the preferred
connection. The pinned account is tried first; on quota/error/lock the
request falls back to the provider's other accounts as usual. Absent,
unknown, or inactive ids are ignored. Applies to single-model, combo,
fusion, and capacity-adapter paths alike.
Each connection row now shows a copyable connection-id chip, and the
provider Connections header carries a one-line tip about the
x-connection-id request header, so account pinning is discoverable
without reading source. Docs: smart-routing.md gains a Claude Code
example (ANTHROPIC_CUSTOM_HEADERS in ~/.claude/settings.json env) and
claude-code.md documents optional account pinning.
Keep both sides: our copy-to-clipboard connection-id hooks and
upstream's proxy dropdown refs/state.
…ocks

detectRequiredCapabilities and the modality strip concern only scanned
top-level content blocks, but claude→openai translates tool_result
images into image_url parts. A tool-returned screenshot therefore
bypassed the vision capacity adapter and hit text-only upstreams
(e.g. Zhipu coding endpoint 400 code 1210: content.type must be text).

- combo.js: recurse scanBlock into tool_result content[]
- modality.js: stripNestedToolResultMedia for vision/pdf/audio caps

@luqman-v1 luqman-v1 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: adds optional x-connection-id request header to pin account selection with automatic fallback to pool on failure. Clean documentation and unit tests.

@nhan14t1

Copy link
Copy Markdown
Author

LGTM: adds optional x-connection-id request header to pin account selection with automatic fallback to pool on failure. Clean documentation and unit tests.

Thanks for the review! I've merged latest master (v0.5.111) into the branch and the full unit suite matches vanilla master (no new failures). Happy to squash/rebase if you prefer.

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