{"id":1920,"library":"azure-ai-inference","title":"Azure AI Inference Client Library","description":"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.","status":"active","version":"1.0.0b9","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/ai/azure-ai-inference","tags":["azure","ai","inference","microsoft","llm","chat","embeddings"],"install":[{"cmd":"pip install azure-ai-inference azure-identity","lang":"bash","label":"Install core library and authentication"}],"dependencies":[],"imports":[{"symbol":"AzureAIInferenceClient","correct":"from azure.ai.inference import AzureAIInferenceClient"},{"symbol":"ChatCompletionsOptions","correct":"from azure.ai.inference.models import ChatCompletionsOptions"},{"symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.ai.inference import AzureAIInferenceClient\nfrom azure.ai.inference.models import ChatCompletionsOptions\nfrom azure.identity import DefaultAzureCredential\n\n# Set your Azure AI Inference service endpoint as an environment variable:\n# export AZURE_AI_INFERENCE_ENDPOINT=\"https://<your-service-name>.inference.ai.azure.com/\"\nendpoint = os.environ.get(\"AZURE_AI_INFERENCE_ENDPOINT\", \"\")\n\nif not endpoint:\n    raise ValueError(\"Please set the AZURE_AI_INFERENCE_ENDPOINT environment variable.\")\n\n# Authenticate using DefaultAzureCredential (checks environment variables, Azure CLI, etc.)\ncredential = DefaultAzureCredential()\n\ntry:\n    # Initialize the client\n    client = AzureAIInferenceClient(endpoint=endpoint, credential=credential)\n\n    # Example: Chat Completion\n    messages = [\n        {\"role\": \"system\", \"content\": \"You are a helpful AI assistant.\"},\n        {\"role\": \"user\", \"content\": \"What is the capital of France?\"},\n    ]\n    chat_options = ChatCompletionsOptions(\n        messages=messages,\n        model=\"gpt-35-turbo\",  # Replace with your deployed model name\n        max_tokens=128\n    )\n\n    print(f\"Sending chat completion request to model: {chat_options.model}...\")\n    response = client.chat.completions(chat_options)\n\n    for choice in response.choices:\n        print(f\"Assistant: {choice.message.content}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure AZURE_AI_INFERENCE_ENDPOINT is set and you are authenticated to Azure (e.g., via `az login`).\")","lang":"python","description":"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."},"warnings":[{"fix":"Refer to the latest documentation and release notes for API changes when upgrading to new beta versions.","message":"This 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.","severity":"breaking","affected_versions":"<1.0.0"},{"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.","message":"Authentication 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.","severity":"gotcha","affected_versions":"All"},{"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/`).","message":"The 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}