Registry / llm-agents / llama-index-llms-azure-openai

llama-index-llms-azure-openai

JSON →
library0.5.5pypypi✓ verified 22d ago

This integration package allows LlamaIndex to utilize Azure OpenAI's Large Language Model (LLM) services. It provides a robust way to connect to and interact with models like GPT-3.5 and GPT-4 deployed on Azure, leveraging LlamaIndex's indexing and querying capabilities. The current version is 0.5.3, with its release cadence tied to updates in the core LlamaIndex library and Azure OpenAI API changes.

pip install llama-index-llms-azure-openai
INSTALL
IMPORT
SIG · LLAMA-INDEX-LLMS-A
L
llama-index-llms-azure-openai
llm-agentspythonv0.5.5
Install
22.2s avg
Import
9096ms
Disk
292MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 7.530s · 280.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 22.2s · import 7.024s · 276MB
292MB installed
● package 292MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AzureOpenAI
from llama_index.llms.azure_openai import AzureOpenAI

This quickstart demonstrates how to initialize the `AzureOpenAI` LLM and use it for a simple completion task. It highlights the required environment variables for Azure OpenAI authentication and configuration, as well as how to set the LLM globally using `Settings` (LlamaIndex v0.10.0+ pattern) or directly interact with the instance.

import os from llama_index.llms.azure_openai import AzureOpenAI from llama_index.core import Settings # Ensure these environment variables are set: # AZURE_OPENAI_API_KEY # AZURE_OPENAI_ENDPOINT (e.g., 'https://YOUR_RESOURCE_NAME.openai.azure.com/') # AZURE_OPENAI_API_VERSION (e.g., '2023-05-15' or '2024-02-15-preview') # AZURE_OPENAI_LLM_DEPLOYMENT_NAME (your deployment name, e.g., 'gpt-35-turbo-deployment') azure_openai_api_key = os.environ.get('AZURE_OPENAI_API_KEY', 'YOUR_AZURE_OPENAI_API_KEY') azure_openai_endpoint = os.environ.get('AZURE_OPENAI_ENDPOINT', 'https://example.openai.azure.com/') azure_openai_api_version = os.environ.get('AZURE_OPENAI_API_VERSION', '2023-05-15') azure_llm_deployment_name = os.environ.get('AZURE_OPENAI_LLM_DEPLOYMENT_NAME', 'your-gpt-35-turbo-deployment') llm = AzureOpenAI( model=azure_llm_deployment_name, # This must be your Azure deployment name api_key=azure_openai_api_key, azure_endpoint=azure_openai_endpoint, api_version=azure_openai_api_version, temperature=0.7, ) # Optionally set as default LLM for LlamaIndex global settings Settings.llm = llm # Make a completion call response = llm.complete("Tell me a short story about a brave knight.") print(response.text)
Debug
Known issues
breakingLlamaIndex core versions 0.10.0 and above deprecate `ServiceContext` for global configuration. LLMs should now be configured either directly on `Settings.llm` or passed explicitly to constructors.
fix
Migrate from `ServiceContext(llm=...)` to `from llama_index.core import Settings; Settings.llm = AzureOpenAI(...)`. For specific components, pass the `llm` instance directly.
affects: llama-index-core>=0.10.0
gotchaThe `model` parameter in `AzureOpenAI` refers to your *Azure deployment name*, not the base OpenAI model name (e.g., 'gpt-35-turbo-deployment', not 'gpt-3.5-turbo'). Incorrectly setting this will lead to errors.
fix
Ensure `model` is set to the exact deployment name as configured in your Azure OpenAI Studio. Also verify `azure_endpoint` is the correct resource endpoint URL and `api_version` matches your deployment's supported version.
affects: All versions
gotchaAzure OpenAI API versions (`api_version`) are date-based and specific (e.g., '2023-05-15'). Using an invalid, unsupported, or outdated version can cause API calls to fail or return unexpected results.
fix
Always use a current and valid `api_version` supported by your Azure OpenAI deployment. Consult Azure's documentation for the latest recommended stable API version. Commonly '2023-05-15' or newer 'preview' versions are used.
affects: All versions
Errors
Common errors & fixes
AuthenticationError: Error code: 401 - {'statusCode': 401, 'message': 'Unauthorized. Access token is missing, invalid, audience is incorrect...'}
This error occurs due to an incorrect Azure OpenAI API key, an invalid endpoint URL, or an outdated API version being used, or when necessary environment variables are not set before the `AzureOpenAI` class is initialized.
fix
Ensure that the `AZURE_OPENAI_API_KEY` (or `OPENAI_API_KEY`), `AZURE_OPENAI_ENDPOINT` (or `OPENAI_API_BASE`), and `OPENAI_API_VERSION` environment variables are correctly set, or pass these parameters directly to the `AzureOpenAI` constructor.

Example:
```python
import os
from llama_index.llms.azure_openai import AzureOpenAI

os.environ["OPENAI_API_KEY"] = "<your-api-key>"
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://<your-resource-name>.openai.azure.com/"
os.environ["OPENAI_API_VERSION"] = "2023-07-01-preview"

# Or pass directly
llm = AzureOpenAI(
    model="gpt-35-turbo",
    deployment_name="my-gpt-deployment", # The 'engine' or deployment name
    api_key=os.environ["OPENAI_API_KEY"],
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_version=os.environ["OPENAI_API_VERSION"],
)
```
InvalidRequestError: The API deployment for this resource does not exist.
This error indicates that the `deployment_name` (often referred to as `engine`) specified when initializing `AzureOpenAI` does not match an active model deployment in your Azure OpenAI Studio, or you're trying to use a model deployment for a different purpose (e.g., an embedding deployment for text generation).
fix
Verify the `deployment_name` (or `engine`) parameter exactly matches the name of your deployed model in Azure OpenAI Studio. Ensure you have deployed both a completion model (for LLMs) and an embedding model (for `AzureOpenAIEmbedding`) if both are used in your application.

Example:
```python
from llama_index.llms.azure_openai import AzureOpenAI

llm = AzureOpenAI(
    model="gpt-35-turbo",
    deployment_name="my-gpt-deployment", # Must match your Azure deployment name
    # ... other parameters
)
```
NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
This error typically means that the Azure OpenAI endpoint or the specific resource you are trying to access (e.g., a model deployment) could not be found at the provided URL. It can also stem from underlying authentication or deployment misconfigurations.
fix
Carefully check the `azure_endpoint` (or `AZURE_OPENAI_ENDPOINT`) for any typos, ensuring it is in the correct format, such as `https://YOUR_RESOURCE_NAME.openai.azure.com/`. Confirm that your Azure OpenAI service is active and the network allows connections to the endpoint. Review related authentication and deployment settings.
ValueError: Unknown model 'gpt-4o'. Please provide a valid OpenAI model name in: gpt-4, gpt-4-32k, gpt-4-1106-preview, gpt-4-0125-preview.
This `ValueError` occurs when the version of `llama-index-llms-azure-openai` or the underlying `openai` library being used does not yet explicitly recognize newer models like 'gpt-4o'.
fix
Update your `llama-index` and `openai` packages to their latest versions to ensure compatibility with newly released models. Use `pip install -U llama-index llama-index-llms-azure-openai openai`. If the model is very new, you might need to wait for a subsequent library update. If it's a custom deployment, ensure the `deployment_name` is correct.
Upgrade
Version history
0.5.5latest on PyPI · released May 8, 2026
Audit
Dependencies
llama-index-corerequiredRequired by all LlamaIndex integrations for core functionality.
openairequiredThe underlying Python client for interacting with the OpenAI API, including Azure OpenAI.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources