Skip to content

fix(openai): send anthropic-version when listing Anthropic models - #317

Open
Danielgfonseca wants to merge 1 commit into
hydropix:mainfrom
Danielgfonseca:fix/anthropic-models-version-header
Open

Danielgfonseca wants to merge 1 commit into
hydropix:mainfrom
Danielgfonseca:fix/anthropic-models-version-header

Conversation

@Danielgfonseca

Copy link
Copy Markdown

Summary

Claude models already translate fine through the OpenAI-compatible provider when the endpoint is Anthropic's OpenAI compatibility layer (https://api.anthropic.com/v1/chat/completions). Only the model list fails: Anthropic's /v1/models answers

HTTP 400 {"type":"error","error":{"type":"invalid_request_error","message":"anthropic-version: header is required"}}

so the web UI shows LLM: Error (HTTP 400 from https://api.anthropic.com/v1/models ...) and an empty model picker, and the model has to be typed by hand.

Change

  • _get_openai_models adds anthropic-version: 2023-06-01 to the /models request when the endpoint host is api.anthropic.com. Anthropic accepts the existing Authorization: Bearer key together with that header and returns the same data[].id shape the picker already parses. Other OpenAI-compatible endpoints are unchanged.
  • docs/PROVIDERS.md: short note on using Anthropic through the OpenAI-compatible provider.

Tests

  • New tests/unit/test_openai_models_anthropic_header.py: the header is sent for the Anthropic endpoint (and the models are returned as openai_connected), and is not sent for a local OpenAI-compatible endpoint. The first test fails without the fix and passes with it.
  • pytest tests/unit: 1898 passed, 1 skipped, 1 failed. The failure is test_path_validator.py::test_reject_path_separator_backslash, which also fails on main on Linux and is unrelated to this change.
  • Checked against the live API: with the header, GET https://api.anthropic.com/v1/models returns 200 and the Claude model list; without it, the 400 above.

Anthropic's OpenAI compatibility layer accepts chat completions with a
plain Bearer key, so translations through the OpenAI-compatible provider
already work with https://api.anthropic.com/v1/chat/completions. Its
/v1/models endpoint, however, answers HTTP 400 ("anthropic-version: header
is required") without that header, so the web UI showed "LLM: Error" and
an empty model list.

Add the header when the endpoint host is api.anthropic.com. The response
uses the same data[].id shape the model picker already parses. Other
OpenAI-compatible endpoints are unchanged.
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