SPB Git

Repository Public

microsoft-foundry.md 12.5 KB 302 lines markdown

1<!-- source: https://docs.x.ai/developers/community/microsoft-foundry (from https://docs.x.ai/llms-full.txt, retrieved 2026-09-19T05:28:55Z) -->2#### Community Integrations34# Microsoft Foundry56Access xAI’s frontier reasoning and agentic models through Azure AI Foundry with enterprise-grade security, governance, and unified billing.78This guide walks through setting up and using Grok models on Microsoft Foundry. Grok models on Foundry give you strong reasoning, native tool use, enterprise authentication through Microsoft Entra ID, Azure-native monitoring, and an OpenAI-compatible API.910Usage is billed through the Azure Marketplace / your Azure subscription. Grok models are delivered through the xAI–Microsoft partnership with Azure-managed endpoints and optional Azure AI Content Safety layers. Review the specific model card in the Foundry catalog for the latest details on data processing, retention, and terms.1112Grok on Foundry works with the official OpenAI Python/TypeScript SDKs, `azure-ai-projects`, LangChain, Semantic Kernel, LlamaIndex, and most OpenAI-compatible frameworks. Streaming, tool calling, and structured outputs are supported.1314## Prerequisites1516Before you begin, ensure you have:1718* An active Azure subscription.19* Access to Azure AI Foundry.20* Sufficient permissions to create or manage Foundry resources/projects and deploy models, typically Contributor or custom roles with model deployment rights.21* Optional but recommended: the Azure CLI installed for resource management and authentication testing.22* Python 3.10+ for the examples in this guide.2324## Install required packages2526```bash customLanguage="bash"27pip install -U openai azure-identity28```2930Optional, for higher-level project client patterns:3132```bash customLanguage="bash"33pip install azure-ai-projects34```3536## Provisioning3738Foundry organizes work into resources for security, billing, and networking, and projects for deployments and collaboration. Create a resource/project first, then deploy one or more Grok model instances inside it.3940The deployment name you choose becomes the value passed in the `model` parameter of your API requests.4142### Create or select a Foundry resource and project43441. Navigate to the Foundry portal.452. Create a new Foundry resource, or select an existing one.463. Within the resource, create a new project if your workflow uses projects.474. Configure access management:48   * Use Microsoft Entra ID with role-based access control (RBAC).49   * Assign the Cognitive Services OpenAI User role, or equivalent, to identities that will call models.50   * Optionally configure private networking through Azure Virtual Network.515. Note your resource name and project name for later.5253The resulting endpoint base will be:5455```text customLanguage="text"56https://{resource-name}.services.ai.azure.com/api/projects/{project-name}/openai/v157```5859### Deploy a Grok model60611. In the Foundry portal, go to your resource or project, then **Models + endpoints**.622. Click **+ Deploy model** → **Deploy base model**, or browse the Model catalog directly and search for “Grok”.633. Browse or search the catalog for the desired Grok model, for example, `grok-4.3`.644. Review the model card for capabilities, context window, tool calling support, safety evaluations, pricing, and deployment options.655. Click **Deploy**.666. Configure deployment settings:67   * **Deployment name:** Choose a clear, stable name, such as `grok-4.3`. This name cannot be changed after creation and is the value you use in the `model` parameter.68   * **Deployment type / SKU:** Select Serverless for pay-as-you-go workloads, or Provisioned Throughput Units (PTU) for predictable high-volume performance.697. Review and select **Deploy**. Wait for the deployment to reach **Ready / Running** status.7071Once deployed, you can test in the built-in Playground, view generated code snippets, manage keys/endpoints if API key auth is enabled, and monitor usage and metrics.7273## Authentication7475Grok on Foundry uses Azure-native authentication. The recommended approach is Microsoft Entra ID (keyless) with `DefaultAzureCredential`. API keys from the portal may also be supported depending on your resource configuration.7677All requests go to your Foundry project’s OpenAI-compatible endpoint:7879```text customLanguage="text"80https://{resource-name}.services.ai.azure.com/api/projects/{project-name}/openai/v181```8283### Recommended: Entra ID authentication8485Use `azure.identity` and `get_bearer_token_provider`. This enables seamless RBAC, managed identities, and avoids secret management.8687```python customLanguage="pythonOpenAISDK"88from azure.identity import DefaultAzureCredential, get_bearer_token_provider89from openai import OpenAI9091project_endpoint = "https://YOUR-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR_PROJECT_NAME"92base_url = project_endpoint.rstrip("/") + "/openai/v1"9394credential = DefaultAzureCredential()95token_provider = get_bearer_token_provider(96    credential,97    "https://ai.azure.com/.default",98)99100client = OpenAI(101    base_url=base_url,102    api_key=token_provider,103)104105response = client.responses.create(106    model="grok-4.3",  # your deployment name107    input="Explain the significance of Grok's tool-calling capabilities for building reliable agents. Be concise but insightful.",108    max_output_tokens=800,109)110111print(response.output_text)112```113114Important:115116* Assign the Cognitive Services OpenAI User, or appropriate role, to the identity running this code.117* `DefaultAzureCredential` handles local development through Azure CLI / VS Code, managed identities, service principals, and other supported flows.118* No `api-version` query parameter is needed; the `/openai/v1` path handles compatibility.119120### Alternative: API key authentication121122If your Foundry resource exposes keys under Keys and Endpoint, copy a primary or secondary key and use it directly as the `api_key`:123124```python customLanguage="pythonOpenAISDK"125client = OpenAI(126    base_url=base_url,127    api_key="your-foundry-api-key-here",128)129```130131Prefer Entra ID + RBAC in production. Never commit keys to source control, and rotate keys regularly.132133## Make your first API call134135### Simple reasoning call136137```python customLanguage="pythonOpenAISDK"138response = client.responses.create(139    model="grok-4.3",140    input="Walk through the first-principles reasoning to determine why reusable rockets dramatically reduce the cost of space access.",141    max_output_tokens=1500,142)143print(response.output_text)144```145146### Tool calling example147148Grok excels at tool use. Here is a pattern for parallel tool calling:149150```python customLanguage="pythonOpenAISDK"151tools = [152    {153        "type": "function",154        "function": {155            "name": "get_current_weather",156            "description": "Get the current weather in a given location",157            "parameters": {158                "type": "object",159                "properties": {160                    "location": {161                        "type": "string",162                        "description": "City and country, e.g., San Francisco, CA",163                    },164                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},165                },166                "required": ["location"],167            },168        },169    },170    {171        "type": "function",172        "function": {173            "name": "search_web",174            "description": "Search the web for recent information",175            "parameters": {176                "type": "object",177                "properties": {178                    "query": {"type": "string"},179                },180                "required": ["query"],181            },182        },183    },184]185186response = client.responses.create(187    model="grok-4.3",188    input="What's the weather like in Palo Alto right now and any major tech news from today?",189    tools=tools,190    # parallel_tool_calls=True,  # enable if supported in your deployment191    max_output_tokens=1000,192)193194print(response)195```196197In a real agent loop, execute the tool calls and continue the conversation with the tool results.198199### Streaming response200201```python customLanguage="pythonOpenAISDK"202stream = client.responses.create(203    model="grok-4.3",204    input="Write a short, helpful onboarding guide for a new engineer joining xAI.",205    max_output_tokens=600,206    stream=True,207)208209for chunk in stream:210    if hasattr(chunk, "choices") and chunk.choices:211        delta = chunk.choices[0].delta212        if hasattr(delta, "content") and delta.content:213            print(delta.content, end="", flush=True)214```215216Start with the Playground in the Foundry portal for rapid prompt iteration, then move to code.217218## Correlation IDs and debugging219220Foundry includes standard Azure request identifiers in response headers, such as `request-id`, `apim-request-id`, and `x-ms-request-id`. When contacting Microsoft or xAI support, include these IDs with your deployment name and approximate timestamp.221222## Feature support and capabilities223224| Capability | Notes |225|---|---|226| Reasoning | Strong first-principles reasoning. “Think mode” style prompting works well. |227| Tool / function calling | Native support for reliable agentic workflows. |228| Structured outputs / JSON mode | Supported. Ask for `response_format`, or instruct JSON explicitly. |229| Streaming | Supported for low-latency user experiences. |230| Long context | Check the specific model card for current context windows. |231| Code generation | Strong performance for code generation and editing tasks. |232233## Safety and responsible AI234235Grok models include xAI’s safety training and alignment. On Foundry, Azure AI Content Safety is available and often enabled by default or easily integrated.236237Before production deployment:238239* Review the full model card and safety benchmark tab in the Foundry catalog.240* Use clear system prompts that define safety boundaries and desired behavior.241* Implement Azure Content Safety filters for input/output where appropriate.242* Conduct your own red-teaming and evaluations.243* Monitor usage and any required mitigations.244245## Limitations246247* Feature parity with the direct xAI API at `api.x.ai` may differ slightly, especially for the latest experimental features.248* Validate vision/multimodal support and exact parameter availability for your chosen model/deployment.249* Rate limits and quotas are managed at the Azure resource level.250251For the authoritative list of supported parameters and behaviors, consult the model card inside Azure AI Foundry and xAI Grok documentation linked from the catalog.252253## Best practices for production254255### Model selection256257* Use full Grok reasoning models for maximum reasoning depth and capability.258* Use balanced reasoning settings for simpler tasks.259* Choose the deployment settings that match your latency, throughput, and cost requirements.260261### Prompting Grok effectively262263* Encourage step-by-step reasoning when needed.264* Specify the desired output format.265* Use clear tool schemas.266267### Cost management268269* Monitor spend in Azure Cost Management + Billing.270* Use serverless for spiky or experimental workloads; use PTU for steady high throughput.271* Right-size the model and deployment type for your expected traffic pattern.272273### Security and compliance274275* Prefer Entra ID + RBAC over long-lived keys.276* Use private endpoints / VNet injection where required.277* Log requests with correlation IDs for auditability.278279### Observability280281* Integrate Azure Monitor, Application Insights, or Log Analytics.282* Track token usage, latency, and error rates per deployment.283284## Troubleshooting285286| Issue | What to check |287|---|---|288| 401 Unauthorized | Missing or incorrect Entra role; wrong token scope; check the `DefaultAzureCredential` chain. |289| 404 Not Found / model not found | Wrong deployment name; it must match exactly what you created in the portal. |290| Deployment stuck in “Running” | Check region quotas, resource health, portal notifications, or try redeploying. |291| Slow responses or high latency | Consider Provisioned Throughput. Check the network path to the Azure region. |292| Tool calls not executing as expected | Verify the tool schema and whether parallel tool calling is enabled/supported for the deployment. |293| Content filtered / blocked | Review Azure Content Safety configuration and your system prompt. Adjust safety thresholds if needed. |294295## Next steps296297* Use the Playground inside your Foundry project.298* Combine Grok with Azure AI Agent Service or popular frameworks such as LangChain, Semantic Kernel, and CrewAI.299* Add retrieval, memory, and orchestration layers for production systems.300* Use Foundry tracing and your internal eval harness to evaluate and improve behavior.301* When migrating from the direct xAI API, update authentication and endpoint configuration. Most prompts and tool schemas transfer with minimal changes.302
Files main
Menu

Theme