Skip to content

Conversation

@threepointone
Copy link
Contributor

@threepointone threepointone commented Dec 21, 2025

Introduces a new GatewayConfig component and updates dependencies to add support for multiple AI providers (OpenAI, Anthropic, Google, xAI). Updates app and server logic to integrate with the new providers and configuration options.

image

Introduces a new GatewayConfig component and updates dependencies to add support for multiple AI providers (Amazon Bedrock, Azure, Cerebras, Cohere, Deepgram, Deepseek, ElevenLabs, Fireworks, Google, Google Vertex, Groq, Mistral, OpenRouter, Perplexity, xAI). Updates app and server logic to integrate with the new providers and configuration options.
@changeset-bot
Copy link

changeset-bot bot commented Dec 21, 2025

⚠️ No Changeset found

Latest commit: 75c6b8a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@claude
Copy link

claude bot commented Dec 21, 2025

Claude Code Review

Issues Found

1. Security: API Keys Stored in Agent State (server.ts:44-49)
Provider API keys, Cloudflare API keys, and Gateway credentials are stored in the agent's state without encryption. This is a security risk:

  • providerApiKey (line 45) - Direct provider API keys
  • gatewayApiKey (line 49) - Cloudflare API key

Recommendation: These sensitive credentials should be stored in environment variables or a secrets manager, not in agent state that could be logged/persisted.

2. Missing Input Validation (server.ts:116-127)
No validation that gatewayAccountId, gatewayId, or gatewayApiKey are well-formed before using them to create gateway connections. Malformed inputs could cause runtime errors.

Recommendation: Add validation before line 130:

if (!this.state.gatewayAccountId || !this.state.gatewayId || !this.state.gatewayApiKey) {
  throw new Error("Missing required gateway credentials");
}

3. Model Name Parsing Fragility (server.ts:118-121)
The model name parsing assumes a specific format:

if (modelName.includes("/")) {
  modelName = modelName.split("/")[1];
}

This is fragile - if the format changes to have multiple slashes (e.g., "provider/version/model"), this breaks. Consider using modelName.split("/").pop() or more robust parsing.

4. xAI Hardcoded Base URL (server.ts:183)
The xAI base URL is hardcoded: baseURL: "https://api.x.ai/v1". If this URL changes or needs to be environment-specific, it requires a code change.

Recommendation: Move to configuration or environment variable.

5. Silent Fallback Behavior (server.ts:193-196)
When external provider configuration is incomplete, the code silently falls back to Workers AI without user notification. Users expecting OpenAI/Anthropic responses will get Workers AI responses instead with no indication of why.

Recommendation: Throw an error or emit a warning when falling back, so users know their configuration is incomplete.

6. Hardcoded Model Lists (UnifiedModelSelector.tsx:10-135)
The external model lists are hardcoded in the component. When providers release new models, this requires a code update and deployment.

Recommendation: Consider fetching available models from an API or configuration file that can be updated without code changes.

Testing Coverage

No test files included in this PR. Given the complexity of multi-provider authentication logic with multiple failure modes, this needs test coverage for:

  • Gateway auth flow
  • Provider key auth flow
  • Fallback behavior when credentials are missing
  • Model name parsing edge cases

Architecture Alignment

The implementation is reasonable but mixing UI state (model selection) with security-sensitive data (API keys) in the same state object is concerning. Consider separating concerns.

Summary

The core functionality looks solid, but there are security and validation issues that should be addressed before merging. The lack of tests for the authentication logic is also a gap.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 21, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@745

commit: 75c6b8a

agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Dec 21, 2025
Sync documentation for PR #745: Add GatewayConfig and expand AI provider support

This update documents the new capability to use AI Gateway with multiple
AI providers (OpenAI, Anthropic, Google, Amazon Bedrock, Azure, and more)
when building agents. The documentation includes:

- List of 15+ supported AI providers through AI Gateway
- Example code showing how to integrate AI Gateway with different providers
- Reference to the AI Playground as a demonstration
- Benefits of routing requests through AI Gateway (logging, caching, etc.)
- Links to BYOK configuration documentation

Related PR: cloudflare/agents#745

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replaces ModelSelector and GatewayConfig with UnifiedModelSelector, enabling selection between Workers AI and external providers (OpenAI, Anthropic, Google) with unified billing or BYOK authentication. Updates Playground state and server logic to support provider/gateway selection, model IDs, and authentication methods. Refactors UI and server to handle new model selection and authentication flows.
Refactored the code generation logic in ViewCodeModal to support Workers AI, OpenAI, Anthropic, and Google providers, with options for both direct API keys and Cloudflare AI Gateway unified billing. Improved string escaping for generated code and updated UI messaging to reflect the selected provider and authentication method.
agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Dec 21, 2025
This update adds detailed documentation for the Cloudflare AI Playground,
covering the new external AI provider support and authentication methods
introduced in PR #745.

Key documentation additions:
- External provider support (OpenAI, Anthropic, Google)
- Two authentication methods:
  - Provider API Key (BYOK - Bring Your Own Key)
  - AI Gateway (Unified Billing)
- Configuration options (system prompt, temperature, model filtering)
- Code export examples for all authentication modes
- MCP server integration guide

Related PR: cloudflare/agents#745

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Introduces xAI as a selectable provider in the AI Playground, including model selection, API key handling, and code generation. xAI models are integrated using the OpenAI-compatible API with appropriate base URL configuration. Updates are made across the app, model selector, code modal, and server logic to support xAI alongside existing providers.
@threepointone threepointone merged commit 3c8dafb into main Dec 22, 2025
5 checks passed
@threepointone threepointone deleted the playground-model-selector branch December 22, 2025 10:05
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.

1 participant