Skip to content

[Feature Request]: plugin hook allowing modification of request body before it is sent #2661

@Zim-Inn

Description

@Zim-Inn

Is your feature request related to a problem? Please describe.
When integrating custom model providers with opencode, some APIs do not support optional fields like "functions": {} or "images": [] in the request payload. These fields, while valid for certain providers (e.g., OpenAI or Anthropic), may cause 400 Bad Request errors when sent to stricter or minimalistic endpoints. Currently, opencode automatically includes these fields based on internal logic, and users have no way to override or customize the payload structure.

Describe the solution you'd like
I propose introducing a configuration option that allows users to define a custom request payload template—either via a JSON schema, a templating system, or a declarative list of enabled/disabled fields. This would give users full control over the shape of the outgoing request, ensuring compatibility with diverse model APIs. Ideally, this could be set per model provider or per model name.

Describe alternatives you've considered

  • Manually modifying the source code to remove unsupported fields (not scalable across upgrades)
  • Using a proxy server to rewrite requests before forwarding (adds complexity and latency)
  • Relying on the provider to ignore unknown fields (not always possible)

Additional context
This feature would greatly improve opencode’s flexibility when working with:

  • Internal LLM gateways with strict schemas
  • Lightweight or experimental model APIs
  • Self-hosted endpoints that reject unknown fields

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