Registry / azure / azure-ai-inference

azure-ai-inference

JSON →
library1.0.0b9pypypi✓ verified 23d ago

The Microsoft Azure AI Inference Client Library for Python provides a unified interface for interacting with various Azure AI inference capabilities, such as chat completions and text embeddings. It is currently in a preview/beta state (version 1.0.0b9) and follows the standard Azure SDK release cadence with frequent updates.

pip install azure-ai-inference azure-identity
INSTALL
IMPORT
SIG · AZURE-AI-INFERENCE
A
azure-ai-inference
azurepythonv1.0.0b9
Install
3.8s avg
Import
Disk
43MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0b9 · 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 0.000s · 44MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.8s · import 0.000s · 44MB
43MB installed
● package 43MB
Code
Verified usage

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

AzureAIInferenceClient
from azure.ai.inference import AzureAIInferenceClient
ChatCompletionsOptions
from azure.ai.inference.models import ChatCompletionsOptions
DefaultAzureCredential
from azure.identity import DefaultAzureCredential

This quickstart demonstrates how to initialize the `AzureAIInferenceClient`, authenticate using `DefaultAzureCredential`, and perform a basic chat completion request. Ensure your `AZURE_AI_INFERENCE_ENDPOINT` environment variable is set and you are logged into Azure CLI or have appropriate service principal environment variables configured.

import os from azure.ai.inference import AzureAIInferenceClient from azure.ai.inference.models import ChatCompletionsOptions from azure.identity import DefaultAzureCredential # Set your Azure AI Inference service endpoint as an environment variable: # export AZURE_AI_INFERENCE_ENDPOINT="https://<your-service-name>.inference.ai.azure.com/" endpoint = os.environ.get("AZURE_AI_INFERENCE_ENDPOINT", "") if not endpoint: raise ValueError("Please set the AZURE_AI_INFERENCE_ENDPOINT environment variable.") # Authenticate using DefaultAzureCredential (checks environment variables, Azure CLI, etc.) credential = DefaultAzureCredential() try: # Initialize the client client = AzureAIInferenceClient(endpoint=endpoint, credential=credential) # Example: Chat Completion messages = [ {"role": "system", "content": "You are a helpful AI assistant."}, {"role": "user", "content": "What is the capital of France?"}, ] chat_options = ChatCompletionsOptions( messages=messages, model="gpt-35-turbo", # Replace with your deployed model name max_tokens=128 ) print(f"Sending chat completion request to model: {chat_options.model}...") response = client.chat.completions(chat_options) for choice in response.choices: print(f"Assistant: {choice.message.content}") except Exception as e: print(f"An error occurred: {e}") print("Ensure AZURE_AI_INFERENCE_ENDPOINT is set and you are authenticated to Azure (e.g., via `az login`).")
Debug
Known issues
breakingThis library is currently in a beta state (`1.0.0b9`). Breaking changes are expected in future releases until it reaches a stable (1.0.0) version. Public API surface and underlying models may change without prior notice.
fix
Refer to the latest documentation and release notes for API changes when upgrading to new beta versions.
affects: <1.0.0
gotchaAuthentication is required and often done via `DefaultAzureCredential`. This credential provider attempts various authentication methods (environment variables, Azure CLI, managed identity). If not configured correctly, it will fail to connect.
fix
Ensure you are logged into Azure CLI (`az login`), or have environment variables like `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and `AZURE_CLIENT_SECRET` set for service principal authentication.
affects: All
gotchaThe Azure AI Inference service endpoint must be provided to the client. This is typically done via the `AZURE_AI_INFERENCE_ENDPOINT` environment variable or passed directly to the `AzureAIInferenceClient` constructor. Forgetting this will lead to connection errors.
fix
Set the `AZURE_AI_INFERENCE_ENDPOINT` environment variable to your specific Azure AI Inference service URL (e.g., `https://<your-service-name>.inference.ai.azure.com/`).
affects: All
Upgrade
Version history
1.0.0b9latest on PyPI · released Feb 15, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
47 hits · last 30 days
node
36
OpenAI (training)
1
Resources
azure-ai-inference — pip install azure-ai-inference · libregistry