Skip to main content
Azure OpenAI provides GPT models through your Azure subscription with enterprise security and compliance.
from agno.agent import Agent
from agno.models.azure import AzureOpenAI

agent = Agent(
    model=AzureOpenAI(id="gpt-4o"),
    markdown=True,
)

agent.print_response("Explain cloud computing", stream=True)

Tool Use

from agno.agent import Agent
from agno.models.azure import AzureOpenAI
from agno.tools.yfinance import YFinanceTools

agent = Agent(
    model=AzureOpenAI(id="gpt-4o"),
    tools=[YFinanceTools(stock_price=True)],
    markdown=True,
)

agent.print_response("What's MSFT's stock price?", stream=True)

Structured Output

from pydantic import BaseModel, Field
from agno.agent import Agent
from agno.models.azure import AzureOpenAI

class Report(BaseModel):
    title: str = Field(..., description="Report title")
    summary: str = Field(..., description="Executive summary")
    key_points: list[str] = Field(..., description="Key points")

agent = Agent(
    model=AzureOpenAI(id="gpt-4o"),
    output_schema=Report,
)

agent.print_response("Create a report on cloud security best practices")

Environment Setup

export AZURE_OPENAI_API_KEY=xxx
export AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
export AZURE_OPENAI_API_VERSION=2024-02-01

Run Examples

git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/92_models/azure/openai

python basic.py
python tool_use.py