Repository navigation
fix(openai): send anthropic-version when listing Anthropic models - #317
Open
Danielgfonseca wants to merge 1 commit into
Open
Danielgfonseca wants to merge 1 commit into
Danielgfonseca wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/modelsanswersso 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_modelsaddsanthropic-version: 2023-06-01to the/modelsrequest when the endpoint host isapi.anthropic.com. Anthropic accepts the existingAuthorization: Bearerkey together with that header and returns the samedata[].idshape the picker already parses. Other OpenAI-compatible endpoints are unchanged.docs/PROVIDERS.md: short note on using Anthropic through the OpenAI-compatible provider.Tests
tests/unit/test_openai_models_anthropic_header.py: the header is sent for the Anthropic endpoint (and the models are returned asopenai_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 istest_path_validator.py::test_reject_path_separator_backslash, which also fails onmainon Linux and is unrelated to this change.GET https://api.anthropic.com/v1/modelsreturns 200 and the Claude model list; without it, the 400 above.