Skip to content

Custom providers: support extra_headers in providers.json (required by OpenCode Go) #3680

Closed

Description

@jkemp814

Problem

providers.json allows a custom OpenAI-compatible provider to override request body fields via extra_body, but there is no way to add request headers. Several gateways require extra headers in addition to Authorization.

Concrete case: OpenCode Go (https://opencode.ai/zen/go/v1) rejects any request without an x-opencode-session header:

400 {'type': 'error', 'error': {'type': 'MissingSessionID', 'message': 'Request is missing x-opencode-session and cannot be routed efficiently. Please see https://opencode.ai/docs/go/#where-can-i-use-it'}}

Per https://opencode.ai/docs/go/ ("Where can I use it?"), non-OpenCode agents are explicitly allowed, but must send a stable x-opencode-session per conversation plus their own distinct User-Agent. There is currently no way to express this in providers.json, so --backend opencode-go fails even with a valid key.

Current workaround

The bundled openai SDK reads OPENAI_CUSTOM_HEADERS, so users can inject the header globally:

export OPENAI_CUSTOM_HEADERS="x-opencode-session: <uuid>
User-Agent: my-agent/1.0"

This works (verified: graphify extract . --backend opencode-go --force succeeds, tokens reported), but it is global rather than per-provider and is not discoverable from the provider config.

Proposal

Allow an optional extra_headers map on a custom provider entry, mirroring extra_body:

{
  "opencode-go": {
    "base_url": "https://opencode.ai/zen/go/v1",
    "default_model": "deepseek-v4-flash",
    "env_key": "OPENCODE_API_KEY",
    "extra_headers": {
      "x-opencode-session": "<uuid>",
      "User-Agent": "graphify/0.9.63"
    }
  }
}

Pass it to the OpenAI client via default_headers at both client-construction sites:

  • _call_openai_compat — client built around llm.py:1389
  • the --dedup-llm OpenAI-compatible path — client built around llm.py:3032

Ignore/drop an authorization entry for consistency with the SDK, which already refuses to let custom headers override an explicit API key.

Notes

  • extra_body is existing precedent for per-provider request customization; this is a small, symmetric addition.
  • Supporting a per-provider User-Agent would also help, since OpenCode Go asks clients to identify themselves rather than send a generic SDK UA.

Verified against graphifyy==0.9.63.

Activity

  1. safishamsi commented on Nov 9, 2026

    @safishamsi
    Member

    Fixed in 0.9.105 (now on PyPI) via #4783: a custom OpenAI-compatible provider's extra_headers are now forwarded as default_headers (Authorization dropped).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions