#Agent SDK doesn't work with Azure hosted model

1 messages · Page 1 of 1 (latest)

hybrid grove
#

I am able to run the model without any issues using the vanilla openai sdk:

Works fine:

...
from openai import AzureOpenAI
client = AzureOpenAI(
    azure_endpoint=endpoint,
    api_key=api_key,
    api_version=api_version,
)
messages = [{"role": "user", "content": "hello"}]
completion = client.chat.completions.create(
    temperature=0.0,
    model=deployment_name,
    timeout=30,
    messages=messages,
)
msg = completion.choices[0].message.content
print(msg) 

But when I try to run it using the Agents sdk:

...
client = AsyncAzureOpenAI(
    azure_endpoint=endpoint,
    api_key=api_key,
    api_version=api_version,
    azure_deployment=deployment_name
)
set_default_openai_client(client)
agent = Agent(
    name="Assistant", 
    instructions="You are a helpful assistant",
)
result = Runner.run_sync(agent, "Hello")
print(result.final_output)

I run into the following error:

openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
[non-fatal] Tracing client error 401: {
  "error": {
    "message": "Incorrect API key provided: ******************************. You can find your API key at https://platform.openai.com/account/api-keys.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}

The key is obviously not wrong since its working with the first code. Any ideas?

turbid ginkgo
#

Hi @hybrid grove this is what I'm trying to do as well, were you able to find any workaround?

turbid ginkgo
#

this is what I'm getting:

openai.BadRequestError: Error code: 400 - {'error': {'code': 'BadRequest', 'message': 'Azure OpenAI Responses API is enabled only for api-version 2025-03-01-preview and later'}}
[non-fatal] Tracing client error 401: {
"error": {
"message": "Incorrect API key provided: BhFKzPXj************************************************************************WaeM. You can find your API key at https://platform.openai.com/account/api-keys.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}

turbid ginkgo
#

mine is already working.

def get_azure_llm():
    return AsyncAzureOpenAI(
        api_version=azure_api_version,
        azure_endpoint=azure_endpoint,
        azure_deployment=azure_deployment,
        api_key=azure_api_key,
    )

...

async def main():
    llm = get_azure_llm()
    set_default_openai_client(llm)

    agent = Agent(
        name="Assistant",
        model="gpt-4o-mini",
        instructions="You are a helpful assistant",
    )

    result = await Runner.run(agent, "Tell me 2 jokes")
    print(result.final_output)


# Run the async function
asyncio.run(main())

#

altho, i still get this error.

turbid ginkgo
hybrid grove
#

I gave up, switched to pydantic_ai, worked without any hassle

turbid ginkgo