fix(opencode-go): strip trailing /v1 from base URL for Anthropic models (#4918)
The Anthropic SDK appends /v1/messages to the base_url, so OpenCode's base URL https://opencode.ai/zen/go/v1 produced a double /v1 path (https://opencode.ai/zen/go/v1/v1/messages), causing 404s for MiniMax models. Strip trailing /v1 when api_mode is anthropic_messages. Also adds MiMo-V2-Pro, MiMo-V2-Omni, and MiniMax-M2.5 to the OpenCode Go model lists per their updated docs. Fixes #4890
This commit is contained in:
@@ -123,6 +123,8 @@ DEFAULT_CONTEXT_LENGTHS = {
|
|||||||
"moonshotai/Kimi-K2-Thinking": 262144,
|
"moonshotai/Kimi-K2-Thinking": 262144,
|
||||||
"MiniMaxAI/MiniMax-M2.5": 204800,
|
"MiniMaxAI/MiniMax-M2.5": 204800,
|
||||||
"XiaomiMiMo/MiMo-V2-Flash": 32768,
|
"XiaomiMiMo/MiMo-V2-Flash": 32768,
|
||||||
|
"mimo-v2-pro": 1048576,
|
||||||
|
"mimo-v2-omni": 1048576,
|
||||||
"zai-org/GLM-5": 202752,
|
"zai-org/GLM-5": 202752,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,10 @@ _PROVIDER_MODELS: dict[str, list[str]] = {
|
|||||||
"opencode-go": [
|
"opencode-go": [
|
||||||
"glm-5",
|
"glm-5",
|
||||||
"kimi-k2.5",
|
"kimi-k2.5",
|
||||||
|
"mimo-v2-pro",
|
||||||
|
"mimo-v2-omni",
|
||||||
"minimax-m2.7",
|
"minimax-m2.7",
|
||||||
|
"minimax-m2.5",
|
||||||
],
|
],
|
||||||
"ai-gateway": [
|
"ai-gateway": [
|
||||||
"anthropic/claude-opus-4.6",
|
"anthropic/claude-opus-4.6",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from hermes_cli import auth as auth_mod
|
from hermes_cli import auth as auth_mod
|
||||||
@@ -168,6 +169,13 @@ def _resolve_runtime_from_pool_entry(
|
|||||||
elif base_url.rstrip("/").endswith("/anthropic"):
|
elif base_url.rstrip("/").endswith("/anthropic"):
|
||||||
api_mode = "anthropic_messages"
|
api_mode = "anthropic_messages"
|
||||||
|
|
||||||
|
# OpenCode base URLs end with /v1 for OpenAI-compatible models, but the
|
||||||
|
# Anthropic SDK prepends its own /v1/messages to the base_url. Strip the
|
||||||
|
# trailing /v1 so the SDK constructs the correct path (e.g.
|
||||||
|
# https://opencode.ai/zen/go/v1/messages instead of .../v1/v1/messages).
|
||||||
|
if api_mode == "anthropic_messages" and provider in ("opencode-zen", "opencode-go"):
|
||||||
|
base_url = re.sub(r"/v1/?$", "", base_url)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"provider": provider,
|
"provider": provider,
|
||||||
"api_mode": api_mode,
|
"api_mode": api_mode,
|
||||||
@@ -700,6 +708,9 @@ def resolve_runtime_provider(
|
|||||||
# (e.g. https://api.minimax.io/anthropic, https://dashscope.../anthropic)
|
# (e.g. https://api.minimax.io/anthropic, https://dashscope.../anthropic)
|
||||||
elif base_url.rstrip("/").endswith("/anthropic"):
|
elif base_url.rstrip("/").endswith("/anthropic"):
|
||||||
api_mode = "anthropic_messages"
|
api_mode = "anthropic_messages"
|
||||||
|
# Strip trailing /v1 for OpenCode Anthropic models (see comment above).
|
||||||
|
if api_mode == "anthropic_messages" and provider in ("opencode-zen", "opencode-go"):
|
||||||
|
base_url = re.sub(r"/v1/?$", "", base_url)
|
||||||
return {
|
return {
|
||||||
"provider": provider,
|
"provider": provider,
|
||||||
"api_mode": api_mode,
|
"api_mode": api_mode,
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ _DEFAULT_PROVIDER_MODELS = {
|
|||||||
"ai-gateway": ["anthropic/claude-opus-4.6", "anthropic/claude-sonnet-4.6", "openai/gpt-5", "google/gemini-3-flash"],
|
"ai-gateway": ["anthropic/claude-opus-4.6", "anthropic/claude-sonnet-4.6", "openai/gpt-5", "google/gemini-3-flash"],
|
||||||
"kilocode": ["anthropic/claude-opus-4.6", "anthropic/claude-sonnet-4.6", "openai/gpt-5.4", "google/gemini-3-pro-preview", "google/gemini-3-flash-preview"],
|
"kilocode": ["anthropic/claude-opus-4.6", "anthropic/claude-sonnet-4.6", "openai/gpt-5.4", "google/gemini-3-pro-preview", "google/gemini-3-flash-preview"],
|
||||||
"opencode-zen": ["gpt-5.4", "gpt-5.3-codex", "claude-sonnet-4-6", "gemini-3-flash", "glm-5", "kimi-k2.5", "minimax-m2.7"],
|
"opencode-zen": ["gpt-5.4", "gpt-5.3-codex", "claude-sonnet-4-6", "gemini-3-flash", "glm-5", "kimi-k2.5", "minimax-m2.7"],
|
||||||
"opencode-go": ["glm-5", "kimi-k2.5", "minimax-m2.5", "minimax-m2.7"],
|
"opencode-go": ["glm-5", "kimi-k2.5", "mimo-v2-pro", "mimo-v2-omni", "minimax-m2.5", "minimax-m2.7"],
|
||||||
"huggingface": [
|
"huggingface": [
|
||||||
"Qwen/Qwen3.5-397B-A17B", "Qwen/Qwen3-235B-A22B-Thinking-2507",
|
"Qwen/Qwen3.5-397B-A17B", "Qwen/Qwen3-235B-A22B-Thinking-2507",
|
||||||
"Qwen/Qwen3-Coder-480B-A35B-Instruct", "deepseek-ai/DeepSeek-R1-0528",
|
"Qwen/Qwen3-Coder-480B-A35B-Instruct", "deepseek-ai/DeepSeek-R1-0528",
|
||||||
|
|||||||
@@ -859,7 +859,9 @@ def test_opencode_zen_claude_defaults_to_messages(monkeypatch):
|
|||||||
|
|
||||||
assert resolved["provider"] == "opencode-zen"
|
assert resolved["provider"] == "opencode-zen"
|
||||||
assert resolved["api_mode"] == "anthropic_messages"
|
assert resolved["api_mode"] == "anthropic_messages"
|
||||||
assert resolved["base_url"] == "https://opencode.ai/zen/v1"
|
# Trailing /v1 stripped for anthropic_messages mode — the Anthropic SDK
|
||||||
|
# appends its own /v1/messages to the base_url.
|
||||||
|
assert resolved["base_url"] == "https://opencode.ai/zen"
|
||||||
|
|
||||||
|
|
||||||
def test_opencode_go_minimax_defaults_to_messages(monkeypatch):
|
def test_opencode_go_minimax_defaults_to_messages(monkeypatch):
|
||||||
@@ -872,7 +874,8 @@ def test_opencode_go_minimax_defaults_to_messages(monkeypatch):
|
|||||||
|
|
||||||
assert resolved["provider"] == "opencode-go"
|
assert resolved["provider"] == "opencode-go"
|
||||||
assert resolved["api_mode"] == "anthropic_messages"
|
assert resolved["api_mode"] == "anthropic_messages"
|
||||||
assert resolved["base_url"] == "https://opencode.ai/zen/go/v1"
|
# Trailing /v1 stripped — Anthropic SDK appends /v1/messages itself.
|
||||||
|
assert resolved["base_url"] == "https://opencode.ai/zen/go"
|
||||||
|
|
||||||
|
|
||||||
def test_opencode_go_glm_defaults_to_chat_completions(monkeypatch):
|
def test_opencode_go_glm_defaults_to_chat_completions(monkeypatch):
|
||||||
|
|||||||
Reference in New Issue
Block a user