From 6a35bd7bb6186d2ee60bbc3de0e2a349b12796f0 Mon Sep 17 00:00:00 2001 From: Matthew Farrellee Date: Sun, 7 Sep 2025 17:00:42 -0400 Subject: [PATCH] chore: update the anthropic inference impl to use openai-python for openai-compat functions (#3366) # What does this PR do? update the Anthropic inference provider to use openai-python for the openai-compat endpoints ## Test Plan ci Co-authored-by: raghotham --- .../providers/remote/inference/anthropic/anthropic.py | 8 +++++++- tests/integration/inference/test_openai_completion.py | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/llama_stack/providers/remote/inference/anthropic/anthropic.py b/llama_stack/providers/remote/inference/anthropic/anthropic.py index 31626082b..0f247218d 100644 --- a/llama_stack/providers/remote/inference/anthropic/anthropic.py +++ b/llama_stack/providers/remote/inference/anthropic/anthropic.py @@ -5,12 +5,13 @@ # the root directory of this source tree. from llama_stack.providers.utils.inference.litellm_openai_mixin import LiteLLMOpenAIMixin +from llama_stack.providers.utils.inference.openai_mixin import OpenAIMixin from .config import AnthropicConfig from .models import MODEL_ENTRIES -class AnthropicInferenceAdapter(LiteLLMOpenAIMixin): +class AnthropicInferenceAdapter(OpenAIMixin, LiteLLMOpenAIMixin): def __init__(self, config: AnthropicConfig) -> None: LiteLLMOpenAIMixin.__init__( self, @@ -26,3 +27,8 @@ class AnthropicInferenceAdapter(LiteLLMOpenAIMixin): async def shutdown(self) -> None: await super().shutdown() + + get_api_key = LiteLLMOpenAIMixin.get_api_key + + def get_base_url(self): + return "https://api.anthropic.com/v1" diff --git a/tests/integration/inference/test_openai_completion.py b/tests/integration/inference/test_openai_completion.py index aee75b21d..df1184f1c 100644 --- a/tests/integration/inference/test_openai_completion.py +++ b/tests/integration/inference/test_openai_completion.py @@ -41,6 +41,7 @@ def skip_if_model_doesnt_support_openai_completion(client_with_models, model_id) # or see the docs at https://console.groq.com/docs/","type":"invalid_request_error","code":"unknown_url"}} "remote::groq", "remote::gemini", # https://generativelanguage.googleapis.com/v1beta/openai/completions -> 404 + "remote::anthropic", # at least claude-3-{5,7}-{haiku,sonnet}-* / claude-{sonnet,opus}-4-* are not supported ): pytest.skip(f"Model {model_id} hosted by {provider.provider_type} doesn't support OpenAI completions.") @@ -73,6 +74,8 @@ def skip_if_doesnt_support_n(client_with_models, model_id): # Error code: 400 - [{'error': {'code': 400, 'message': 'Only one candidate can be specified in the # current model', 'status': 'INVALID_ARGUMENT'}}] "remote::gemini", + # https://docs.anthropic.com/en/api/openai-sdk#simple-fields + "remote::anthropic", ): pytest.skip(f"Model {model_id} hosted by {provider.provider_type} doesn't support n param.")