Fetch available Anthropic models. Returns models that support tool use.
()
| 406 | ) |
| 407 | @pga_login_required |
| 408 | def get_anthropic_models(): |
| 409 | """ |
| 410 | Fetch available Anthropic models. |
| 411 | Returns models that support tool use. |
| 412 | """ |
| 413 | from pgadmin.llm.utils import get_anthropic_api_key, get_anthropic_api_url |
| 414 | |
| 415 | api_key = get_anthropic_api_key() |
| 416 | api_url = get_anthropic_api_url() |
| 417 | if not api_key and not api_url: |
| 418 | return make_json_response( |
| 419 | data={'models': [], 'error': 'No API key configured'}, |
| 420 | status=200 |
| 421 | ) |
| 422 | |
| 423 | try: |
| 424 | models = _fetch_anthropic_models(api_key, api_url) |
| 425 | return make_json_response(data={'models': models}, status=200) |
| 426 | except LLMApiError as e: |
| 427 | return make_json_response( |
| 428 | data={'models': [], 'error': str(e)}, |
| 429 | status=200 |
| 430 | ) |
| 431 | except Exception: |
| 432 | return make_json_response( |
| 433 | data={'models': [], |
| 434 | 'error': 'Failed to fetch Anthropic models. ' |
| 435 | 'Check the API key and URL configuration.'}, |
| 436 | status=200 |
| 437 | ) |
| 438 | |
| 439 | |
| 440 | @blueprint.route( |
nothing calls this directly
no test coverage detected