Azure OpenAI enterprise pricing
Quick answer
Azure OpenAI enterprise pricing is usage-based, billed per 1,000 tokens processed with rates varying by model and region. Use the AzureOpenAI SDK with your enterprise subscription to monitor usage and control costs effectively.
PREREQUISITES
Python 3.8+Azure OpenAI enterprise subscriptionpip install openai>=1.0Azure OpenAI endpoint and API key
Setup
Install the openai Python package and set environment variables for your Azure OpenAI endpoint and API key.
- Set
AZURE_OPENAI_API_KEYwith your Azure OpenAI key. - Set
AZURE_OPENAI_ENDPOINTwith your Azure OpenAI resource endpoint URL. - Set
AZURE_OPENAI_DEPLOYMENTwith your deployed model name.
pip install openai>=1.0 output
Collecting openai Downloading openai-1.x.x-py3-none-any.whl Installing collected packages: openai Successfully installed openai-1.x.x
Step by step
Use the AzureOpenAI client to call your deployed model and track usage for cost management.
import os
from openai import AzureOpenAI
client = AzureOpenAI(
api_key=os.environ["AZURE_OPENAI_API_KEY"],
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
api_version="2024-02-01"
)
response = client.chat.completions.create(
model=os.environ["AZURE_OPENAI_DEPLOYMENT"],
messages=[{"role": "user", "content": "What is the pricing model for Azure OpenAI enterprise?"}]
)
print(response.choices[0].message.content) output
Azure OpenAI enterprise pricing is based on the number of tokens processed, with rates varying by model and region. You are billed monthly based on your usage.
Common variations
You can use different deployed models by changing the model parameter. For asynchronous calls, use async client methods. Streaming responses are supported by setting stream=True in the request.
import asyncio
from openai import AzureOpenAI
async def async_chat():
client = AzureOpenAI(
api_key=os.environ["AZURE_OPENAI_API_KEY"],
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
api_version="2024-02-01"
)
stream = await client.chat.completions.acreate(
model=os.environ["AZURE_OPENAI_DEPLOYMENT"],
messages=[{"role": "user", "content": "Explain Azure OpenAI pricing."}],
stream=True
)
async for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)
asyncio.run(async_chat()) output
Azure OpenAI enterprise pricing is usage-based, charged per 1,000 tokens processed. Pricing varies by model and region. You can monitor usage in the Azure portal.
Troubleshooting
If you encounter authentication errors, verify your AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT environment variables are correct. For deployment not found errors, confirm your deployment name matches AZURE_OPENAI_DEPLOYMENT. Check Azure portal quotas and billing limits if usage is unexpectedly blocked.
Key Takeaways
- Azure OpenAI enterprise pricing is usage-based, billed per 1,000 tokens processed.
- Use the AzureOpenAI client with your endpoint and deployment for API calls.
- Monitor usage and costs via the Azure portal to avoid unexpected charges.