Skip to content

feat(drivers): support custom HTTP headers for OpenAI-compatible providers - #1294

Open
lifaon74 wants to merge 1 commit into
RightNow-AI:mainfrom
lifaon74:feat/provider-custom-headers
Open

lifaon74 wants to merge 1 commit into
RightNow-AI:mainfrom
lifaon74:feat/provider-custom-headers

Conversation

@lifaon74

Copy link
Copy Markdown

Problem

The OpenCode Go gateway (https://opencode.ai/zen/go/v1) now requires an x-opencode-session header on every request (see the official requirements and this write-up on the breaking change). Without it, every completion fails with:

API error (400): {"type":"error","error":{"type":"MissingSessionID","message":"Request is missing x-opencode-session and cannot be routed efficiently."}}

OpenFang's OpenAIDriver already supports extra headers via with_extra_headers() (used hard-coded for GitHub Copilot), but there is no configuration path that populates it, so OpenCode Go subscriptions cannot be used as a provider at all.

Solution

Add an optional headers table to [default_model] and [[fallback_providers]]:

[default_model]
provider = "openai"
model = "glm-5.3-flash"
api_key_env = "OPENCODE_API_KEY"
base_url = "https://opencode.ai/zen/go/v1"

[default_model.headers]
x-opencode-session = "openfang-my-instance"
  • Plumbed through DriverConfig and applied in create_driver() to OpenAI-compatible drivers via the existing with_extra_headers().
  • Resolved like subprocess_timeout_secs: from [default_model] for the primary provider, from the matching [[fallback_providers]] entry for fallbacks, None otherwise (headers belong to a specific endpoint, not inheritable).
  • Values are redacted in Debug output (length only), consistent with api_key handling.
  • Docs (docs/configuration.md) and openfang.toml.example updated.

Testing

  • cargo check on openfang-types, openfang-runtime, openfang-kernel, openfang-api, openfang-cli, openfang-migrate
  • cargo test: 388 (types) + 995 (runtime) pass, including 4 new config round-trip tests
  • cargo fmt --check clean, clippy 0 warnings on touched files
  • End-to-end verified against the real OpenCode Go endpoint with x-opencode-session set

…iders

Add an optional headers table to [default_model] and [[fallback_providers]]
in config.toml. DriverConfig picks it up and OpenAI-compatible drivers
apply the pairs via with_extra_headers (e.g. x-opencode-session required
by the OpenCode Go endpoint). Ignored by non-HTTP and subprocess drivers.
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.

1 participant