Skip to content

Conversation

@englishm
Copy link

@englishm englishm commented Dec 29, 2025

Summary

Fixes the sdk.chat is not a function error when using Cloudflare AI Gateway as a provider.

  • Changed sdk.chat(modelID) to sdk.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

The @ai-sdk/openai-compatible SDK does not have a .chat() method - it
only exposes .languageModel() and .chatModel(). This caused the error:

  sdk.chat is not a function. (In 'sdk.chat(modelID)', 'sdk.chat' is undefined)

Change to use .languageModel() which is the standard method available
on all AI SDK providers.

Fixes sst#4977
@englishm
Copy link
Author

Written by Anthropic Claude Opus 4.5 in opencode itself:
https://opncd.ai/share/jQrbNtGy

@englishm
Copy link
Author

cc: @elithrar

@elithrar
Copy link
Contributor

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!)

@englishm
Copy link
Author

englishm commented Dec 29, 2025

@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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloudflare AI Gateway Not Working

2 participants