Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Oct 3, 2025

Summary

This PR addresses Issue #8488 by enabling custom model IDs when using the Anthropic API provider with custom base URLs. This enhancement allows users to leverage services like z.ai that provide Anthropic-compatible endpoints with their own custom models (e.g., glm-4.6-cc-max, glm-4.5v).

Changes

Backend (src/api/providers/anthropic.ts)

  • Modified getModel() method to detect when a custom base URL is configured
  • When using a custom base URL, any model ID is now accepted (not just predefined Claude models)
  • Provides sensible defaults for unknown models (200k context window, conservative feature flags)
  • Maintains backward compatibility - predefined models still work with their specific configurations

Frontend (webview-ui/src/components/settings/providers/Anthropic.tsx)

  • Added ModelPicker component that appears when custom base URL is enabled
  • Users can now select from predefined models or enter any custom model ID
  • Added helpful text explaining the custom model capability

UI Flow (webview-ui/src/components/settings/ApiOptions.tsx)

  • Prevents duplicate model selectors when Anthropic provider uses custom base URL

Testing

  • Added comprehensive test suite in src/api/providers/__tests__/anthropic.custom-models.spec.ts
  • Tests cover standard models, custom models, auth token handling, and API calls
  • All existing tests continue to pass

Use Case

Users of services like z.ai can now:

  1. Select Anthropic as their API provider
  2. Enable custom base URL and enter their service endpoint (e.g., https://api.z.ai/api/anthropic)
  3. Enter any custom model ID their service supports (e.g., glm-4.6-cc-max)
  4. Use these custom models with full Roo Code functionality

Testing Instructions

  1. Go to Settings → API Provider → Select "Anthropic"
  2. Enter your API key
  3. Check "Use custom base URL"
  4. Enter a custom URL (e.g., https://api.z.ai/api/anthropic)
  5. Notice the model picker now appears
  6. Type a custom model name (e.g., glm-4.6-cc-max)
  7. Select "Use custom model: glm-4.6-cc-max" from the dropdown
  8. The custom model should now be usable

Backward Compatibility

  • ✅ Existing Anthropic configurations continue to work unchanged
  • ✅ Standard Claude models work with or without custom base URLs
  • ✅ No breaking changes to the API

Fixes #8488


Important

Adds support for custom model IDs and base URLs for the Anthropic provider, with frontend and backend changes ensuring backward compatibility.

  • Backend (src/api/providers/anthropic.ts):
    • getModel() now supports custom model IDs with custom base URLs, providing default settings for unknown models.
    • Maintains predefined model configurations for known models, even with custom base URLs.
  • Frontend (webview-ui/src/components/settings/providers/Anthropic.tsx):
    • Introduces ModelPicker for custom model selection when a custom base URL is set.
    • Adds explanatory text for custom model capabilities.
  • UI Flow (webview-ui/src/components/settings/ApiOptions.tsx):
    • Prevents duplicate model selectors for Anthropic with custom base URLs.
  • Testing:
    • New tests in src/api/providers/__tests__/anthropic.custom-models.spec.ts for custom model handling, including API calls and token counting.
  • Backward Compatibility:
    • Existing Anthropic configurations and standard models remain functional without changes.

This description was created by Ellipsis for a995d97. You can customize this summary. It will automatically update as commits are pushed.

- Updated AnthropicHandler to accept any model ID when using custom base URL
- Added ModelPicker to Anthropic UI component for custom model selection
- Prevents model selector duplication in ApiOptions when using custom Anthropic URL
- Added comprehensive tests for custom model functionality

This enables using services like z.ai with custom models (e.g., glm-4.6-cc-max)
through Anthropic-compatible endpoints.

Fixes #8488
@roomote roomote bot requested review from cte, jr and mrubens as code owners October 3, 2025 12:41
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request UI/UX UI/UX related or focused labels Oct 3, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 3, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Self-review: audited my own diff and found a race condition between me and myself.

{t("settings:providers.anthropicUseAuthToken")}
</Checkbox>
<div className="text-sm text-vscode-descriptionForeground mt-1">
When using a custom base URL, you can use any model ID including custom models from services
Copy link
Contributor Author

Choose a reason for hiding this comment

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

P3 – Hardcoded UI string bypasses i18n. Consider adding an i18n key (e.g., settings:providers.anthropicCustomModelHelp) and using t(...) to stay consistent with the rest of the settings UI.

@daniel-lxs
Copy link
Member

#8488 (comment)

@daniel-lxs daniel-lxs closed this Oct 28, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 28, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Oct 28, 2025
@daniel-lxs daniel-lxs deleted the feat/anthropic-custom-models branch October 28, 2025 16:46
@cobra91
Copy link

cobra91 commented Oct 28, 2025

?

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

Labels

enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files. UI/UX UI/UX related or focused

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Don't fix model list for Anthropic custom base URL on only claude-x models

5 participants