fix: cloudflare-ai-gateway sdk.chat undefined error
Summary
Fixes the sdk.chat is not a function error when using Cloudflare AI Gateway as a provider.
- Changed
sdk.chat(modelID)tosdk.languageModel(modelID)in the cloudflare-ai-gateway custom loader
Problem
The @ai-sdk/openai-compatible SDK (which Cloudflare AI Gateway uses per models.dev) does not have a .chat() method. It only exposes .languageModel() and .chatModel(). This caused the error:
ERROR sdk.chat is not a function. (In 'sdk.chat(modelID)', 'sdk.chat' is undefined)
The original PR #5174 was merged with sdk.chat(), even though the author noted in a comment that they had "fixed the way we call the openai-compatible SDK (.languageModel)" - that fix was never actually committed.
Solution
Use .languageModel() which is the standard method available on all AI SDK providers and matches how other providers in this file work (see bedrock, google-vertex, sap-ai-core, etc.).
Testing
Tested locally with Cloudflare AI Gateway credentials - models now load and respond correctly.
This fix was developed entirely using opencode itself 🎉
Fixes #6262
Written by Anthropic Claude Opus 4.5 in opencode itself:
https://opncd.ai/share/jQrbNtGy
cc: @elithrar
Which models did you get with this + which version of OpenCode?
(Tested this prior and it worked, so wondering why this/how this got missed!)
@elithrar:
Which models did you get with this + which version of OpenCode?
(Tested this prior and it worked, so wondering why this/how this got missed!)
This was broken for me on 1.0.203, 1.0.204, and 1.0.207. Tested with Opus 4.5 and Sonnet 4.5 (broken before this change, working after).
My suspicion was that a dependency might have shifted and broken this, but Claude thinks you forgot to push a commit you had locally to make this same change before your PR was merged.
@rekram1-node could I get a favor + have this merged? 🙏
@elithrar yes ofc, I read through this and thought it wasnt necessary given your comments but lgtm so sure!