Skip to content

[Feature Request] Allow provider/model selection via HTTP API for sessions #3517

Closed

Description

@crayment

Problem

When using the OpenCode HTTP API programmatically (e.g., for sub-agent orchestration), there's no way to specify which AI provider or model to use per session or message. All sessions use the server's configured default model.

Use Case

Building a parent-agent system that spawns multiple sub-agents via the OpenCode HTTP API:

  • Cost optimization: Use cheaper models (e.g., Haiku) for simple tasks like linting
  • Performance: Use fast models for quick queries, powerful models for complex analysis
  • Testing: Verify behavior across different providers/models
  • Parallel workflows: Run different sub-agents with different models simultaneously

Current Behavior

# Creating a session - no way to specify model
POST /session?directory=...
{"title": "My Task"}

# Sending a message - model selection ignored
POST /session/:id/message?directory=...
{"parts": [...], "providerID": "anthropic", "modelID": "claude-haiku-4-5"}
# ^ These fields are ignored, uses default model

Result: Always uses server default (e.g., claude-sonnet-4-5-20250929)

Desired Behavior

Allow provider/model selection via API:

Option 1: Set at session creation

POST /session?directory=...
{
  "title": "Fast Task",
  "providerID": "anthropic",
  "modelID": "claude-haiku-4-5"
}

Option 2: Set per message

POST /session/:id/message?directory=...
{
  "parts": [{"type": "text", "text": "..."}],
  "providerID": "anthropic",
  "modelID": "claude-haiku-4-5"
}

Option 3: Both (most flexible)

Set default at session creation, override per message if needed.

Current Workaround

None - must accept whatever default model the server is configured with.

Additional Context

The /config/providers endpoint already exposes all available providers and models, so clients can discover what's available. We just need a way to actually select them.

API currently tested:

  • ✅ /config/providers - shows all models
  • ❌ Session creation with providerID/modelID - ignored
  • ❌ Message with providerID/modelID - ignored
  • ❌ /session/:id/init endpoint - only for AGENTS.md generation

This would be especially valuable for programmatic workflows where different tasks have different model requirements.

Activity

  1. github-actions commented on Oct 28, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. rekram1-node commented on Oct 28, 2025

    @rekram1-node
    Collaborator
  3. crayment commented on Oct 29, 2025

    @crayment
    ContributorAuthor

    Thanks @rekram1-node! I tested it and confirmed it works perfectly with both anthropic/claude-sonnet-4-5-20250929 and openai/gpt-5. Really appreciate the quick response and the code example - that was exactly what I needed. This unlocks some great use cases for programmatic sub-agent orchestration. 🎉

  4. rekram1-node commented on Oct 29, 2025

    @rekram1-node
    Collaborator

    ofc, no problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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