opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE]: Add query parameter support for custom OpenAI-compatible providers

Open UranA1 opened this issue 1 week ago • 3 comments

Feature hasn't been suggested before.

  • [x] I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem: When configuring custom OpenAI-compatible providers, there's currently no way to add query parameters to API requests. Some OpenAI-compatible APIs require query parameters (e.g., ?api-version=2024-01-01) rather than or in addition to headers for configuration. Currently, the @ai-sdk/openai-compatible package only supports:

  • baseURL
  • apiKey
  • headers
  • fetch (custom function)

Use Case: Some providers like Azure OpenAI Service variants or custom enterprise APIs require query parameters for:

  • API versioning (api-version)
  • Tenant/workspace identifiers
  • Feature flags or capabilities
  • Authentication tokens in query string format

Current Workaround: The only workaround is implementing a custom fetch function that intercepts requests and manually appends query parameters, which is not straightforward or well-documented.

Proposed Solution: Add a queryParams option to provider configuration:

{
  provider: {
    custom-provider: {
      npm: @ai-sdk/openai-compatible,
      api: https://api.example.com/v1,
      options: {
        apiKey: your-key,
        queryParams: {
          api-version: 2024-01-01,
          tenant: my-org
        }
      }
    }
  }
}

These parameters would be automatically appended to all requests made to the provider.

Benefits:

  • Cleaner configuration for APIs requiring query parameters
  • No need for custom fetch implementations
  • Consistent with how headers are already handled
  • Enables support for more OpenAI-compatible API variants

Implementation Location: The change would likely need to be made in:

  • packages/opencode/src/provider/provider.ts (lines 892-975, where SDK options are processed)
  • packages/opencode/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts (where URLs are constructed)

UranA1 avatar Jan 07 '26 12:01 UranA1