Skip to content

Bedrock Claude models can't work with OpenAI SDK in python

0

hi, I'm trying to use Claude Haiku 4.5 by using Bedrock but I can't find an easy way to call it using OpenAI SDK in Python. Could you please help me confirm if these are the only options to make it work bc none of them uses OpenAI SDK https://docs.aws.amazon.com/bedrock/latest/userguide/service_code_examples_bedrock-runtime_anthropic_claude.html? Thanks

asked a month ago101 views
2 Answers
1

Actually, you can use the OpenAI SDK in Python with Bedrock Claude models, but this capability is currently limited to specific models. Based on the available information, the OpenAI SDK compatibility is supported for OpenAI's open weight models (like gpt-oss-120b and gpt-oss-20b) on Amazon Bedrock, where you can configure the OpenAI SDK to point to Bedrock endpoints.

However, for Claude models specifically, the standard approach is to use the AWS SDK (Boto3) rather than the OpenAI SDK. The documentation you referenced shows the correct methods for invoking Claude models, which include using either the native InvokeModel API or the Converse API through Boto3.

If you're looking for OpenAI SDK compatibility with Bedrock, you would need to:

  1. Set the OPENAI_BASE_URL to your Bedrock endpoint
  2. Use an Amazon Bedrock API key for authentication

But this pattern is documented for OpenAI models on Bedrock, not for Claude models. For Claude Haiku 4.5 and other Anthropic models on Bedrock, you'll need to use the Boto3 SDK with either the invoke_model or converse methods as shown in the documentation you found. These are indeed the standard and recommended approaches for working with Claude models on Amazon Bedrock.
Sources
OpenAI open weight models now available on AWS | AWS News Blog
Amazon Bedrock Runtime examples using SDK for Python (Boto3) - AWS SDK Code Examples
Reinforcement fine-tuning on Amazon Bedrock with OpenAI-Compatible APIs: a technical walkthrough | Artificial Intelligence

answered a month ago
EXPERT
reviewed a month ago
1

Hello.

You can view a list of available models using the following command.
I tried running the command, but it may not be usable because the model ID for Claude could not be found.
https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-mantle.html

export OPENAI_API_KEY=bedrock-api-key-
export OPENAI_BASE_URL="https://bedrock-mantle.us-east-1.api.aws/v1"

curl -X GET $OPENAI_BASE_URL/models \
   -H "Authorization: Bearer $OPENAI_API_KEY"

{"data":[{"created":1763923865,"id":"mistral.ministral-3-14b-instruct","object":"model","owned_by":"system"},{"created":1764460800,"id":"qwen.qwen3-coder-30b-a3b-instruct","object":"model","owned_by":"system"},{"created":1764460800,"id":"openai.gpt-oss-20b","object":"model","owned_by":"system"},{"created":1764460800,"id":"google.gemma-3-12b-it","object":"model","owned_by":"system"},{"created":1764460800,"id":"qwen.qwen3-32b","object":"model","owned_by":"system"},{"created":1764460800,"id":"openai.gpt-oss-safeguard-120b","object":"model","owned_by":"system"},{"created":1769396433,"id":"minimax.minimax-m2.5","object":"model","owned_by":"system"},{"created":1765065600,"id":"nvidia.nemotron-nano-3-30b","object":"model","owned_by":"system"},{"created":1763769600,"id":"nvidia.nemotron-nano-12b-v2","object":"model","owned_by":"system"},{"created":1768780800,"id":"nvidia.nemotron-super-3-120b","object":"model","owned_by":"system"},{"created":1764460800,"id":"qwen.qwen3-coder-480b-a35b-instruct","object":"model","owned_by":"system"},{"created":1771770206,"id":"zai.glm-5","object":"model","owned_by":"system"},{"created":1764460800,"id":"moonshotai.kimi-k2-thinking","object":"model","owned_by":"system"},{"created":1764460800,"id":"mistral.magistral-small-2509","object":"model","owned_by":"system"},{"created":1764460800,"id":"google.gemma-3-27b-it","object":"model","owned_by":"system"},{"created":1764460800,"id":"mistral.voxtral-mini-3b-2507","object":"model","owned_by":"system"},{"created":1764460800,"id":"openai.gpt-oss-120b","object":"model","owned_by":"system"},{"created":1771804800,"id":"writer.palmyra-vision-7b","object":"model","owned_by":"system"},{"created":1763923896,"id":"mistral.mistral-large-3-675b-instruct","object":"model","owned_by":"system"},{"created":1764460800,"id":"mistral.voxtral-small-24b-2507","object":"model","owned_by":"system"},{"created":1769558400,"id":"zai.glm-4.7","object":"model","owned_by":"system"},{"created":1763923750,"id":"mistral.ministral-3-8b-instruct","object":"model","owned_by":"system"},{"created":1769385600,"id":"deepseek.v3.2","object":"model","owned_by":"system"},{"created":1764460800,"id":"qwen.qwen3-next-80b-a3b-instruct","object":"model","owned_by":"system"},{"created":1769396433,"id":"minimax.minimax-m2.1","object":"model","owned_by":"system"},{"created":1764460800,"id":"deepseek.v3.1","object":"model","owned_by":"system"},{"created":1764460800,"id":"minimax.minimax-m2","object":"model","owned_by":"system"},{"created":1764460800,"id":"openai.gpt-oss-safeguard-20b","object":"model","owned_by":"system"},{"created":1769644800,"id":"zai.glm-4.7-flash","object":"model","owned_by":"system"},{"created":1764460800,"id":"qwen.qwen3-235b-a22b-2507","object":"model","owned_by":"system"},{"created":1764460800,"id":"zai.glm-4.6","object":"model","owned_by":"system"},{"created":1763769600,"id":"nvidia.nemotron-nano-9b-v2","object":"model","owned_by":"system"},{"created":1764460800,"id":"google.gemma-3-4b-it","object":"model","owned_by":"system"},{"created":1770163200,"id":"qwen.qwen3-coder-next","object":"model","owned_by":"system"},{"created":1765843200,"id":"mistral.devstral-2-123b","object":"model","owned_by":"system"},{"created":1763923654,"id":"mistral.ministral-3-3b-instruct","object":"model","owned_by":"system"},{"created":1769558400,"id":"moonshotai.kimi-k2.5","object":"model","owned_by":"system"},{"created":1764460800,"id":"qwen.qwen3-vl-235b-a22b-instruct","object":"model","owned_by":"system"}],"object":"list"}
EXPERT
answered a month ago
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.