Skip to content

fix(llmcore): support opencode.ai Zen/Go endpoints (x-opencode-session header) - #831

Open
tuxdio wants to merge 1 commit into
lsdefine:mainfrom
tuxdio:feat/opencode-go-session
Open

tuxdio wants to merge 1 commit into
lsdefine:mainfrom
tuxdio:feat/opencode-go-session

Conversation

@tuxdio

@tuxdio tuxdio commented Oct 11, 2026

Copy link
Copy Markdown

Summary

Adds first-class support for opencode.ai Zen/Go endpoints to llmcore.py.

opencode's gateway requires every request to carry a stable x-opencode-session header and a self-reported User-Agent; without them the OpenAI-compatible paths return 400 MissingSessionID. Its Anthropic /v1/messages path also only accepts x-api-key authentication — a non-sk-ant- key currently falls through to Authorization: Bearer and gets 401 Missing API key.

Changes

  1. _oc_session_id() + _OC_SIDS — stable per-model session id (reused across requests in-process; config can override via session_id/extra_headers).
  2. BaseSession.__init__ — when api_base contains opencode.ai, auto-inject extra_headers['x-opencode-session'] and replace the default Claude CLI UA with GenericAgent/1.0.
  3. _openai_stream() — merge extra_headers so OpenAI / chat_completions / responses paths send the session header.
  4. ClaudeSession.raw_ask() — merge extra_headers for the Anthropic /v1/messages path.
  5. NativeClaudeSession.raw_ask() — also send x-api-key when api_base contains opencode.ai (covers non-sk-ant- keys).

Verification (2026-10-12, local)

  • OpenAI path (kimi-k3, grok-4.7 via /v1/responses) — ✅ reachable with this patch; upstream llmcore.py alone fails with 400 MissingSessionID.
  • Anthropic native path (minimax-m3 via /v1/messages, api_key_header non-standard) — ✅ 1.6s first token; upstream alone fails with 401 Missing API key.
  • Patch is git diff HEAD -- llmcore.py (14 insertions / 1 deletion, 5 hunks), applied on current main (6e0c54f).

Notes

mykey.py configs need no extra_headers/session_id fields — the patch injects them automatically when api_base contains opencode.ai.

…n header)

opencode.ai /v1 (OpenAI and Anthropic paths) requires a stable
x-opencode-session header per request and a self-reported User-Agent;
without it the endpoint returns 400 MissingSessionID. Native paths also
require x-api-key even when the key is not sk-ant- prefixed.

- add _oc_session_id() stable per-model session id
- BaseSession: inject extra_headers when api_base contains opencode.ai,
  override default UA with GenericAgent/1.0
- _openai_stream()/ClaudeSession.raw_ask(): merge extra_headers
- NativeClaudeSession: send x-api-key for opencode.ai api_base
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