Implement dynamic model detection using Anthropic's /v1/models endpoint

Created on 16 June 2025, about 2 months ago

Problem/Motivation

Currently, the AI Provider Anthropic module hardcodes available models in the getConfiguredModels() method. This approach has several limitations:

  1. Manual maintenance required: Every time Anthropic releases new models (like Claude 4), the module needs to be manually updated
  2. Delayed support: Users cannot access new models until maintainers update the module
  3. Missing models: As seen with Claude 4 models (claude-opus-4-20250514, claude-sonnet-4-20250514), new models are not immediately available

Anthropic provides a /v1/models endpoint that returns a list of all available models, but this capability is not being utilized.

Steps to reproduce

  1. Install AI Provider Anthropic module
  2. Configure with a valid API key
  3. Check available models in the UI
  4. Notice that Claude 4 models (claude-opus-4-20250514, claude-sonnet-4-20250514) are not listed despite being available in Anthropic's API

Proposed resolution

Implement dynamic model detection by:

  1. Adding a method to query Anthropic's /v1/models endpoint
  2. Caching the results to avoid excessive API calls
  3. Falling back to hardcoded models if the API call fails
  4. Optionally allowing site administrators to refresh the model list

The implementation would query GET https://api.anthropic.com/v1/models with appropriate headers and cache the results.

Remaining tasks

  • Implement the fetchAvailableModels() method
  • Add caching mechanism with configurable TTL
  • Create fallback mechanism to hardcoded models
  • Add error handling and logging
  • Update existing getConfiguredModels() to use dynamic fetching
  • Write tests for the new functionality
  • Update documentation

User interface changes

No UI changes required. Models will automatically appear in existing model selection dropdowns.

Optional: Add a "Refresh models" button in the AI Provider configuration page to clear the cache and fetch updated models.

API changes

  • New protected method: fetchAvailableModels()
  • New protected method: getHardcodedModels() (refactored from current implementation)
  • No changes to public API - maintains backward compatibility

Data model changes

  • New cache entry: ai_provider_anthropic.models
  • Possible new config option for cache TTL (default: 24 hours)
Feature request
Status

Active

Version

1.1

Component

Code

Created by

🇺🇸United States camoa

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024