Skip to content

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

Closed

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

Activity

  1. github-actions commented on Sep 18, 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 Sep 18, 2025

    @rekram1-node
    Collaborator

    We have a plugin system we should just add addition hooks / expanding existing if current ones dont suffice and that would allow you to manipulate things before requests are sent

  3. Zim-Inn commented on Sep 18, 2025

    @Zim-Inn
    Author

    We have a plugin system we should just add addition hooks / expanding existing if current ones dont suffice and that would allow you to manipulate things before requests are sent

    Fine. I see that plugin doc., but how to create a request body decorator plugin? That doc in your website is too crude.

  4. rekram1-node commented on Sep 18, 2025

    @rekram1-node
    Collaborator

    Sorry I was just kinda saying how support for this would work didn't mean to sound dismissive of your ask.

    Would something like the following work for you:

    ability to intercept request bodies to the LLM provider before they are sent and edit them and then the edited version be sent to server?

  5. Zim-Inn commented on Sep 19, 2025

    @Zim-Inn
    Author

    Would something like the following work for you:

    ability to intercept request bodies to the LLM provider before they are sent and edit them and then the edited version be sent to server?

    Yes, it is what I need.


    BTW, you are so polite.

  6. rekram1-node commented on Sep 19, 2025

    @rekram1-node
    Collaborator

    Happy to help, perfect yeah that sounds like something we can do for you

  7. changed the title [-]Feature Request: Allow Customizable Request Payload Templates for Model Compatibility[/-] [+][Feature Request]: plugin hook allowing modification of request body before it is sent[/+] on Sep 23, 2025
  8. NightRare commented on Nov 27, 2025

    @NightRare

    Just wondering is there any update on this one? @rekram1-node thanks

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

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