Skip to content

Adding support for Claude Models via Azure AI Foundry #97

@shivamkainth

Description

@shivamkainth

Question summary

Now Antropic models are available via azure too, but the function is unable to communicate with the model

Details

This is following the different URL Format of Chat Completions i.e. /v1/messages

curl -X POST "https://<my_resource_name>.openai.azure.com/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AZURE_API_KEY" \
-H "anthropic-version:2023-06-01" \
-d '{
    "messages" : [
        {
                "role": "user",
                "content": "I am going to Paris, what should I see?"
        },
        {
                "role": "assistant",
                "content": "Paris, the capital of France, is known for its stunning architecture, tpwers and buildings."
        },
        {
                "role": "user",
                "content": "What is so great about #1?"
        }
],
     "max_completion_tokens" : 2048,
     "temperature" : 1,
     "thinking" : {
        "type": "disabled"
},
    "model": "claude4"
}'

or

from anthropic import AnthropicFoundry

endpoint = "https://<my_resource_name>.openai.azure.com/anthropic"
deployment_name = "claude4"
api_key = "<your-api-key>"

client = AnthropicFoundry(
    api_key=api_key,
    base_url=endpoint
)

message = client.messages.create(
    model=deployment_name,
    messages=[
        {"role": "user", "content": "What is the capital of France?"}
    ],
    max_tokens=1024,
)

print(message.content)

What have you tried?

But when i am using this function it is giving error like this:
Error: Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.
But when using Pure Python and Anthropic SDK, it is working just fine, CURL Command is giving the same issue.
can you please help in implemementing this for Anthropic SDK as well ?
Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions