Azure OpenAI

Use OpenAI models through Azure with Kern agents.

Use OpenAI models through Azure's infrastructure. Learn more here.

Azure OpenAI provides access to OpenAI's models like GPT-4o, gpt-5-mini, and more.

Authentication

Navigate to Azure OpenAI on the Azure Portal and create a service. Then, using the Azure AI Studio portal, create a deployment and set your environment variables:

1export AZURE_OPENAI_API_KEY=***
2export AZURE_OPENAI_ENDPOINT=*** # Of the form https://<your-resource-name>.openai.azure.com/openai/deployments/<your-deployment-name>
3# Optional:
4# export AZURE_OPENAI_DEPLOYMENT=***
1setx AZURE_OPENAI_API_KEY *** # Of the form https://<your-resource-name>.openai.azure.com/openai/deployments/<your-deployment-name>
2setx AZURE_OPENAI_ENDPOINT ***
3# Optional:
4# setx AZURE_OPENAI_DEPLOYMENT ***

Example

Use AzureOpenAI with your Agent:

1from kern.agent import Agent
2from kern.models.azure import AzureOpenAI
3from os import getenv
4
5agent = Agent(
6 model=AzureOpenAI(id="gpt-5-mini"),
7 markdown=True
8)
9
10# Print the response on the terminal
11agent.print_response("Share a 2 sentence horror story.")

Prompt caching

Prompt caching will happen automatically using our AzureOpenAI model. You can read more about how OpenAI handle caching in their docs.

Advanced Examples

View more examples here.

Parameters

ParameterTypeDefaultDescription
idstr(required)The deployment name or model name to use
namestr"AzureOpenAI"The name of the model
providerstr"Azure"The provider of the model
api_keyOptional[str]NoneThe API key for Azure OpenAI (defaults to AZURE_OPENAI_API_KEY env var)
api_versionOptional[str]"2024-10-21"The API version to use
azure_endpointOptional[str]NoneThe Azure endpoint URL (defaults to AZURE_OPENAI_ENDPOINT env var)
azure_deploymentOptional[str]NoneThe deployment name (defaults to AZURE_OPENAI_DEPLOYMENT env var)
base_urlOptional[str]NoneAlternative base URL for the service
azure_ad_tokenOptional[str]NoneAzure AD token for authentication
azure_ad_token_providerOptional[Any]NoneAzure AD token provider for authentication
default_headersOptional[Dict[str, str]]NoneDefault headers to include in all requests
default_queryOptional[Dict[str, Any]]NoneDefault query parameters to include in all requests

AzureOpenAI also supports the parameters of OpenAI.