Repository navigation
feat(ai): a named method for every provider API - #60926
Conversation
There was a problem hiding this comment.
Looks good. Every new method points at a route the provider already uses, and model(...) routes exactly as before. I compared Cloudflare AI Gateway's model dispatch on the base and with this PR for openai/, anthropic/ (including the . → - rewrite), workers-ai/ and plain ids, with the native gateway and with a custom baseURL; the model id and route matched in every case. I also checked that each new method resolves to the expected route. The new type test fails on the base and passes here, bun run test in packages/ai passes (2002/0) and typecheck:tsc passes.
Public API: the only changes are new exports in @opencode/ai. Namespaces gain chat (OpenRouter, DigitalOcean, Cohere, Alibaba, Azure, AmazonBedrockMantle, CloudflareAIGateway), responses (Alibaba, Azure, AmazonBedrockMantle, CloudflareAIGateway), messages (Alibaba, AmazonBedrockMantle, CloudflareAIGateway) and gemini (Google). configure() results gain chat (OpenRouter, DigitalOcean), gemini (Google), and chat/responses/messages (CloudflareAIGateway). Nothing is removed or renamed, so it's backwards compatible.
Problem
Some provider APIs could only be reached through
model(...)or only onconfigure(). OpenRouter and DigitalOcean default to Chat Completions but had nochat, Google had no name for Gemini, Cloudflare AI Gateway exposed its three routes only throughmodel's prefix dispatch, and Alibaba, Azure, Cohere and Bedrock Mantle had their selectors only onconfigure().Change
Every text API a provider already routes to now has a method named after it, both on the namespace and on
configure().model(...)behaves exactly as before; no routes were added.configure()before → afterAlibaba, Azure and Cloudflare AI Gateway have no default provider (they need a region, resource or account), so their namespace methods take settings like their existing
model. Cloudflare AI Gateway'smodelnow dispatches to the new methods.Full table after (every provider in
src/providers.ts)Out of scope
Cohere's native v2 chat (its
modeldefault) has no method name in the package, so it staysmodelonly. Single-API providers are unchanged.Verification
test/provider-api-methods.types.ts:[OpenAI, XAI, Venice, OpenRouter, DigitalOcean]callp.chat("x")in a loop and pass it toai.generate; fails without the changebun run typecheckandbun run typecheck:tscinpackages/aiandpackages/corebun run testinpackages/ai: 2002 pass, 0 failbun run check: 35/35Visual
Added by the opencode bot (AI-generated).
Public API: adds named API methods (chat/responses/messages/gemini) to several @opencode/ai provider namespaces and configure() results (backwards compatible)