Skip to content

Server API ignores agent's configured model when only agent parameter is passed #7099

@cyhhao

Description

@cyhhao

Description

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:

{
  "model": "anthropic/claude-opus-4-5",
  "agent": {
    "build": {
      "model": "anthropic/claude-opus-4-5"
    },
    "plan": {
      "model": "openai/gpt-5.2",
      "reasoningEffort": "xhigh"
    }
  }
}

API Request:

curl -X POST "http://localhost:4096/session/{session_id}/message" \
  -H "x-opencode-directory: /path/to/project" \
  -H "Content-Type: application/json" \
  -d '{"agent": "plan", "parts": [{"type": "text", "text": "Hello"}]}'

Expected behavior:
The server should use openai/gpt-5.2 (the model configured for the plan agent).

Actual behavior:
The server uses google/gemini-3-pro-preview (or another fallback model), ignoring the agent's configured model.

Evidence from API response:

{
  "info": {
    "modelID": "gemini-3-pro-preview",
    "providerID": "google",
    "agent": "plan"
  }
}

Additional context:

  • 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

  1. Configure agent-specific models in ~/.config/opencode/opencode.json:

    {
      "agent": {
        "plan": {
          "model": "openai/gpt-5.2"
        }
      }
    }
  2. Start the OpenCode server: opencode serve

  3. Create a session via API:

    curl -X POST "http://localhost:4096/session" \
      -H "x-opencode-directory: /path/to/project" \
      -H "Content-Type: application/json" \
      -d '{}'
  4. Send a message with only the agent parameter:

    curl -X POST "http://localhost:4096/session/{session_id}/message" \
      -H "x-opencode-directory: /path/to/project" \
      -H "Content-Type: application/json" \
      -d '{"agent": "plan", "parts": [{"type": "text", "text": "What model are you?"}]}'
  5. Observe that the response uses a different model than configured for the plan agent

Screenshot and/or share link

No response

Operating System

macOS 15.5

Terminal

No response

Metadata

Metadata

Assignees

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