[PR #12391] fix: Recursively compute reasoning variants for Vercel AI Gateway provider based on model id #14202

Closed
opened 2026-02-16 18:19:00 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12391

State: closed
Merged: No


Fixes #12630

I (naturally) wrote this PR with OpenCode, spending a lot of time in planning mode, and tightly supervising/reviewing the output. The description here is my own.

OpenCode session: https://opncd.ai/share/eweVVrvn

What does this PR do?

Vercel AI Gateway wasn't working with the built-in reasoning variants. There were reasoning variants defined, but they didn't do anything, because the reasoning options were being passed into providerOptions.gateway, which doesn't accept reasoning options.

The gateway is a bit weird in that it just passes through providerOptions for other providers: https://ai-sdk.dev/providers/ai-sdk-providers/ai-gateway#provider-specific-options

This adds a providerOptions field to the gateway options that gets merged into the object returned by ProviderTransform.providerOptions(...). The providerOptions field lets you define upstream provider-specific options inside of the gateway options object. (See the docs for an example)

The built-in variant logic is extended to recursively call itself with a fake model object that matches a likely upstream provider for the given model id. This is pretty hacky, but it required minimal changes to implement.

One of the challenges for the built-in variant logic is that we don't know what exact provider will be used for a specific request. Right now, this code just takes a best-guess.

The more correct thing to do would be to pessimistically set the reasoning options to whatever options are supported by the combination of providers that are upstream of AI gateway for a given model. However, that's potentially very complicated, so this PR does not attempt to do that.

Moving parseModel

I moved parseModel into transform.ts, so I could use it there. This avoids a circular dependency (which would probably be fine, but Claude preferred to do it this way).

How did you verify your code works?

Typecheck, unit tests, and manual testing:

Screenshot 2026-02-05 at 5 08 33 PM

Prior to this change, I didn't get any thinking output and the AI Gateway dashboard always showed zero reasoning tokens.

I tested this change with both Opus 4.6 and GPT 5.2.

I tested the example included in the documentation, and observed that GPT 5.2 would produce more or less output based on the verbosity option supplied.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12391 **State:** closed **Merged:** No --- Fixes #12630 *I (naturally) wrote this PR with OpenCode, spending a lot of time in planning mode, and tightly supervising/reviewing the output. The description here is my own.* OpenCode session: https://opncd.ai/share/eweVVrvn ### What does this PR do? Vercel AI Gateway wasn't working with the built-in reasoning variants. There were reasoning variants defined, but they didn't do anything, because the reasoning options were being passed into `providerOptions.gateway`, which doesn't accept reasoning options. The gateway is a bit weird in that it just passes through `providerOptions` for other providers: https://ai-sdk.dev/providers/ai-sdk-providers/ai-gateway#provider-specific-options This adds a `providerOptions` field to the gateway options that gets merged into the object returned by `ProviderTransform.providerOptions(...)`. The `providerOptions` field lets you define upstream provider-specific options inside of the gateway options object. (See the docs for an example) The built-in variant logic is extended to recursively call itself with a fake model object that matches a likely upstream provider for the given model id. This is pretty hacky, but it required minimal changes to implement. One of the challenges for the built-in variant logic is that we don't know what exact provider will be used for a specific request. Right now, this code just takes a best-guess. The more correct thing to do would be to pessimistically set the reasoning options to whatever options are supported by the combination of providers that are upstream of AI gateway for a given model. However, that's potentially very complicated, so this PR does not attempt to do that. ### Moving `parseModel` I moved `parseModel` into `transform.ts`, so I could use it there. This avoids a circular dependency (which would probably be fine, but Claude preferred to do it this way). ### How did you verify your code works? Typecheck, unit tests, and manual testing: <img width="1109" height="738" alt="Screenshot 2026-02-05 at 5 08 33 PM" src="https://github.com/user-attachments/assets/4334b1ad-3c92-404b-9804-00b38d2ef694" /> Prior to this change, I didn't get any thinking output and the AI Gateway dashboard always showed zero reasoning tokens. I tested this change with both Opus 4.6 and GPT 5.2. I tested the example included in the documentation, and observed that GPT 5.2 would produce more or less output based on the verbosity option supplied.
yindo added the pull-request label 2026-02-16 18:19:00 -05:00
yindo closed this issue 2026-02-16 18:19:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14202