You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Server API ignores agent's configured model when only agent parameter is passed #7099
When using the OpenCode Server HTTP API to send a message with only the agent parameter (without explicitly passing model), the server does not use the agent's configured default model from opencode.json. Instead, it falls back to the global default model.
Configuration in ~/.config/opencode/opencode.json:
The /agent API endpoint returns native agents (build, plan) without their configured model field, even though the model is specified in opencode.json
The /config API only returns custom agents (like code-reviewer) with their model configuration, not native agents
According to the documentation, agent-specific models should override the global default
This issue affects users who want to use different models for different agents via the Server API, which is a common use case for building integrations and plugins.
Plugins
opencode-antigravity-auth@1.2.7
OpenCode version
1.1.3
Steps to reproduce
Configure agent-specific models in ~/.config/opencode/opencode.json:
This issue might be a duplicate of existing issues. Please check:
Bug: SDK Messages cause switch back to default model #4901: SDK Messages cause switch back to default model - Similar issue where API/SDK interactions ignore the user's manually selected model and revert to the agent's default model
All of these appear to be related to the same underlying issue: the Server API and other interfaces not properly respecting agent-specific model configurations from opencode.json when only the agent parameter is passed without an explicit model.
Feel free to ignore if your specific case differs from these.
After extensive code analysis, I investigated the reported issue where the Server API allegedly ignores an agent's configured model when only the agent parameter is passed.
Key files examined:
packages/opencode/src/session/prompt.ts - Model resolution logic at line 806
packages/opencode/src/agent/agent.ts - Agent state initialization and model configuration at line 184
packages/opencode/src/config/config.ts - Configuration loading and merging
packages/opencode/src/server/server.ts - API endpoint handlers
packages/opencode/test/agent/agent.test.ts - Existing tests that confirm functionality
Findings:
The model resolution logic at prompt.ts:806 is correct: model: input.model ?? agent.model ?? (await lastModel(input.sessionID))
The agent configuration loading at agent.ts:184 correctly applies models: if (value.model) item.model = Provider.parseModel(value.model)
Tests at test/agent/agent.test.ts confirm that agent model configuration works correctly (see test "custom agent config overrides native agent properties" at line 136)
The configuration loading from global (~/.config/opencode/) and project directories works correctly
Possible explanations for the reported issue:
Config file location - The config might not be at the expected path (~/.config/opencode/opencode.json)
State caching - If the server was started before the config was created/modified, the cached state wouldn't include the updated config (restart required)
Environment-specific issue - XDG paths might differ on certain systems
Conclusion:
I could not identify a specific bug in the codebase that would cause this behavior. The code logic appears correct and tests pass. The issue is likely environmental or related to state caching behavior. If this is a recurring issue for users, it might be worth adding better diagnostics or documentation about config loading and caching.
I discovered a separate but related issue. When explicitly passing model parameters to the API, the API reports using the requested model, but the actual model responding is different.
Test Results
Requested Model
API reports modelID
Model self-identifies as
claude-opus-4-5
claude-opus-4-5
claude-sonnet-4-20250514
claude-sonnet-4-5
claude-sonnet-4-5
claude-sonnet-4-20250514
claude-haiku-4-5
claude-haiku-4-5
claude-sonnet-4-20250514
gpt-4o (OpenAI)
gpt-4o
✅ Works correctly
Reproduction
# Request claude-opus-4-5
curl -s -X POST 'http://127.0.0.1:4096/session/{session_id}/message' \
-H 'Content-Type: application/json' \
-H 'x-opencode-directory: /tmp/test' \
-d '{"parts": [{"type": "text", "text": "Respond with ONLY your model name/version, nothing else."}], "model": {"providerID": "anthropic", "modelID": "claude-opus-4-5"}}'# Response shows modelID: claude-opus-4-5# But the text response is: "claude-sonnet-4-20250514"
Hypothesis
The opencode-antigravity-auth@1.2.7 plugin may be routing all Anthropic requests to claude-sonnet-4 regardless of which model is requested. This could be:
An OAuth tier/permission limitation
A bug in the plugin's model routing logic
This is a different issue from the agent-config-model problem described in the original issue. Should I open a separate issue for this?
Activity
github-actions commentedon Jan 6, 2026
This issue might be a duplicate of existing issues. Please check:
All of these appear to be related to the same underlying issue: the Server API and other interfaces not properly respecting agent-specific model configurations from opencode.json when only the agent parameter is passed without an explicit model.
Feel free to ignore if your specific case differs from these.
rekram1-node commentedon Jan 6, 2026
/oc if this is a bug, find it and fix it
opencode-agent commentedon Jan 6, 2026
Summary of Analysis:
After extensive code analysis, I investigated the reported issue where the Server API allegedly ignores an agent's configured model when only the
agentparameter is passed.Key files examined:
packages/opencode/src/session/prompt.ts- Model resolution logic at line 806packages/opencode/src/agent/agent.ts- Agent state initialization and model configuration at line 184packages/opencode/src/config/config.ts- Configuration loading and mergingpackages/opencode/src/server/server.ts- API endpoint handlerspackages/opencode/test/agent/agent.test.ts- Existing tests that confirm functionalityFindings:
prompt.ts:806is correct:model: input.model ?? agent.model ?? (await lastModel(input.sessionID))agent.ts:184correctly applies models:if (value.model) item.model = Provider.parseModel(value.model)test/agent/agent.test.tsconfirm that agent model configuration works correctly (see test "custom agent config overrides native agent properties" at line 136)~/.config/opencode/) and project directories works correctlyPossible explanations for the reported issue:
~/.config/opencode/opencode.json)Conclusion:
I could not identify a specific bug in the codebase that would cause this behavior. The code logic appears correct and tests pass. The issue is likely environmental or related to state caching behavior. If this is a recurring issue for users, it might be worth adding better diagnostics or documentation about config loading and caching.
opencode session | github run
rekram1-node commentedon Jan 6, 2026
This seems to be a bug w/ ur plugin, works fine without it
cyhhao commentedon Jan 7, 2026
Additional Finding: Anthropic Model Routing Bug
I discovered a separate but related issue. When explicitly passing model parameters to the API, the API reports using the requested model, but the actual model responding is different.
Test Results
modelIDclaude-opus-4-5claude-opus-4-5claude-sonnet-4-20250514claude-sonnet-4-5claude-sonnet-4-5claude-sonnet-4-20250514claude-haiku-4-5claude-haiku-4-5claude-sonnet-4-20250514gpt-4o(OpenAI)gpt-4oReproduction
Hypothesis
The
opencode-antigravity-auth@1.2.7plugin may be routing all Anthropic requests toclaude-sonnet-4regardless of which model is requested. This could be:This is a different issue from the agent-config-model problem described in the original issue. Should I open a separate issue for this?
fix(tui): wait for model store before auto-submitting --prompt
Steffen025 commentedon Feb 3, 2026
Confirming this issue WITHOUT any plugins
I'm experiencing the exact same behavior in a fresh setup without the antigravity plugin.
My Setup
.opencode/agents/with explicit model configAgent Definition (
.opencode/agents/PerplexityResearcher.md)Reproduction
Expected
Agent uses
perplexity/sonaras configured.Actual
Agent runs on session default (Claude), ignoring the agent's
modelfield entirely.Evidence
The code at
task.ts:102-105should respectagent.model:But the agent lookup by
subagent_typestring doesn't seem to load the custom agent definition from.opencode/agents/.This is a real bug affecting custom multi-provider agent setups, not just plugin-related.
github-actions commentedon Apr 5, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.