Skip to content

fix(sse): use x-api-key for opencode-go minimax messages requests - #733

Merged
diegosouzapw merged 1 commit into
diegosouzapw:mainfrom
ottodevs:fix/opencode-go-minimax-auth
Mar 29, 2026
Merged

diegosouzapw merged 1 commit into
diegosouzapw:mainfrom
ottodevs:fix/opencode-go-minimax-auth

Conversation

@ottodevs

Copy link
Copy Markdown
Contributor

Summary

Fix OpenCode Go MiniMax auth for Anthropic-style /messages requests.

Root cause

OpenCode Go mixes protocol families by model:

  • glm-5 and kimi-k2.5 use OpenAI-style /chat/completions
  • minimax-m2.5 and minimax-m2.7 use Anthropic-style /messages

OmniRoute already routed the MiniMax Go models to /messages, but OpencodeExecutor still sent Authorization: Bearer ..., which caused upstream 401 Missing API key errors.

For OpenCode Go MiniMax /messages, upstream expects:

  • x-api-key: <key>
  • anthropic-version: 2023-06-01

Changes

  • update open-sse/executors/opencode.ts
    • send x-api-key for Claude-targeted OpenCode Go requests
    • keep Authorization: Bearer ... for the remaining OpenCode Go request formats
  • update tests/unit/opencode-executor.test.mjs
    • assert the correct MiniMax Go header behavior

Validation

Validated with:

  • direct curl repro against OpenCode Go endpoints
  • node --import tsx/esm --test tests/unit/opencode-executor.test.mjs
  • npm run typecheck:core
  • npm run build

Notes

This fix is intentionally narrow:

  • it preserves current behavior for glm-5 and kimi-k2.5
  • it only changes auth header selection for OpenCode Go requests using Claude target format

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the OpencodeExecutor to use the x-api-key header instead of Authorization when the request format is set to "claude", while also ensuring the anthropic-version header is included. The unit tests have been updated to reflect these changes. A review comment suggests restructuring the header assignment logic to improve readability and better separate authentication concerns from format-specific settings.

Comment thread open-sse/executors/opencode.ts Outdated
Comment on lines 47 to 54
if (this._requestFormat === "claude") {
if (key) {
headers["x-api-key"] = key;
}
headers["anthropic-version"] = "2023-06-01";
} else if (key) {
headers["Authorization"] = `Bearer ${key}`;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While this logic is correct, it could be slightly restructured for better readability and separation of concerns. You could handle setting authentication headers based on the key's presence first, and then handle other format-specific headers. This avoids nesting the key check within the format check and makes the logic for setting auth headers more self-contained.

    if (key) {
      if (this._requestFormat === "claude") {
        headers["x-api-key"] = key;
      } else {
        headers["Authorization"] = `Bearer ${key}`;
      }
    }

    if (this._requestFormat === "claude") {
      headers["anthropic-version"] = "2023-06-01";
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

OpenCode Go mixes request protocols by model family:

   - `glm-5` and `kimi-k2.5` use OpenAI-style `/chat/completions`
   - `minimax-m2.5` and `minimax-m2.7` use Anthropic-style `/messages`

   OmniRoute already routed MiniMax Go models to `/messages`, but the
   executor still sent `Authorization: Bearer ...`, which caused upstream
   `401 Missing API key` errors.

   This changes `OpencodeExecutor` to send:
   - `x-api-key` + `anthropic-version` for Claude-targeted OpenCode Go requests
   - `Authorization: Bearer ...` for the remaining OpenCode Go request formats

   Also updates unit coverage to assert the correct header behavior for
   MiniMax Go models.

   Validated with:
   - direct curl repro against OpenCode Go endpoints
   - `node --import tsx/esm --test tests/unit/opencode-executor.test.mjs`
   - `npm run typecheck:core`
   - `npm run build`
@ottodevs
ottodevs force-pushed the fix/opencode-go-minimax-auth branch from 2b4f82f to d411992 Compare March 29, 2026 04:16
@kilo-code-bot

kilo-code-bot Bot commented Mar 29, 2026

Copy link
Copy Markdown

Code Review Summary

Status: No New Issues Found | Recommendation: Merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0

Analysis

The PR correctly implements the auth header fix for OpenCode Go MiniMax models:

  1. open-sse/executors/opencode.ts - The conditional logic properly selects x-api-key header for Claude-target format (/messages endpoint) and Authorization: Bearer for other formats (/chat/completions)

  2. tests/unit/opencode-executor.test.mjs - Test properly updated to assert x-api-key header for Claude format

  3. Security - The fix correctly uses x-api-key as required by OpenCode Go MiniMax /messages endpoint per the PR description

Existing Comment

There is one existing inline comment suggesting a code style reorganization (medium priority). This is a valid stylistic suggestion but does not affect functionality - the current implementation is correct.

Files Reviewed (2 files)
  • open-sse/executors/opencode.ts - 0 issues
  • tests/unit/opencode-executor.test.mjs - 0 issues

@diegosouzapw
diegosouzapw merged commit b94c0c7 into diegosouzapw:main Mar 29, 2026
1 check passed
@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks @ottodevs for this great contribution! 🎉 The fix is now merged and will be part of the next release. We appreciate your effort!

@diegosouzapw diegosouzapw mentioned this pull request Apr 22, 2026
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
…egosouzapw#733)

OpenCode Go mixes request protocols by model family:

   - `glm-5` and `kimi-k2.5` use OpenAI-style `/chat/completions`
   - `minimax-m2.5` and `minimax-m2.7` use Anthropic-style `/messages`

   OmniRoute already routed MiniMax Go models to `/messages`, but the
   executor still sent `Authorization: Bearer ...`, which caused upstream
   `401 Missing API key` errors.

   This changes `OpencodeExecutor` to send:
   - `x-api-key` + `anthropic-version` for Claude-targeted OpenCode Go requests
   - `Authorization: Bearer ...` for the remaining OpenCode Go request formats

   Also updates unit coverage to assert the correct header behavior for
   MiniMax Go models.

   Validated with:
   - direct curl repro against OpenCode Go endpoints
   - `node --import tsx/esm --test tests/unit/opencode-executor.test.mjs`
   - `npm run typecheck:core`
   - `npm run build`
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…egosouzapw#733)

OpenCode Go mixes request protocols by model family:

   - `glm-5` and `kimi-k2.5` use OpenAI-style `/chat/completions`
   - `minimax-m2.5` and `minimax-m2.7` use Anthropic-style `/messages`

   OmniRoute already routed MiniMax Go models to `/messages`, but the
   executor still sent `Authorization: Bearer ...`, which caused upstream
   `401 Missing API key` errors.

   This changes `OpencodeExecutor` to send:
   - `x-api-key` + `anthropic-version` for Claude-targeted OpenCode Go requests
   - `Authorization: Bearer ...` for the remaining OpenCode Go request formats

   Also updates unit coverage to assert the correct header behavior for
   MiniMax Go models.

   Validated with:
   - direct curl repro against OpenCode Go endpoints
   - `node --import tsx/esm --test tests/unit/opencode-executor.test.mjs`
   - `npm run typecheck:core`
   - `npm run build`
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