Skip to content

fix: show clear error when Cloudflare provider env vars are missing#20399

Open
mchenco wants to merge 2 commits intoanomalyco:devfrom
mchenco:mchen/fix-cloudflare-provider-errors
Open

fix: show clear error when Cloudflare provider env vars are missing#20399
mchenco wants to merge 2 commits intoanomalyco:devfrom
mchenco:mchen/fix-cloudflare-provider-errors

Conversation

@mchenco
Copy link
Copy Markdown
Contributor

@mchenco mchenco commented Apr 1, 2026

Issue for this PR

Fixes #20398

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When users connect cloudflare-workers-ai or cloudflare-ai-gateway via /connect, the API key is saved in auth. But the custom loaders also need CLOUDFLARE_ACCOUNT_ID (and CLOUDFLARE_GATEWAY_ID for gateway) as env vars.

When those env vars are missing, the loaders return { autoload: false } without a getModel. Since the provider is already in the providers map from auth, the loader result is still processed (result.autoload || providers[providerID]), but no model loader gets registered. When the user sends a message, the fallback calls sdk.languageModel(model.api.id) which crashes with sdk.languageModel is not a function.

The fix adds a getModel to the early returns that throws a clear error naming the missing env var with the export command, e.g.:

CLOUDFLARE_ACCOUNT_ID is missing. Set it with: export CLOUDFLARE_ACCOUNT_ID=<your-account-id>

How did you verify your code works?

  • All 70 existing provider tests pass
  • Ran a verification script that simulates /connect auth without CLOUDFLARE_ACCOUNT_ID, confirms the provider loads from auth, and verifies getLanguage throws the clear error instead of crashing

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@mchenco mchenco marked this pull request as draft April 1, 2026 05:01
@mchenco mchenco force-pushed the mchen/fix-cloudflare-provider-errors branch 4 times, most recently from 82b7d5e to ea21b48 Compare April 1, 2026 05:08
Copy link
Copy Markdown
Contributor

@elithrar elithrar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from our/the Cloudflare side. Makes the missing env vars more explicit.

@mchenco mchenco force-pushed the mchen/fix-cloudflare-provider-errors branch from bf6a847 to ea21b48 Compare April 1, 2026 19:05
@mchenco mchenco force-pushed the mchen/fix-cloudflare-provider-errors branch from ea21b48 to 4aa1bd6 Compare April 1, 2026 19:20
@mchenco mchenco marked this pull request as ready for review April 1, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Cloudflare providers show 'sdk.languageModel is not a function' when CLOUDFLARE_ACCOUNT_ID is missing

2 participants