- Familiar languages: Use the SDK for the language you already know (Python, .NET, etc.).
- Predictable structure: The typical pattern is initialize client → build messages/params → call API → process response.
- Fine-grained control: Tune generation with parameters such as max_tokens, temperature, and top_p.
- Sync and async options: Choose synchronous or asynchronous clients depending on your app architecture.

- Import the SDK package for your language.
- Initialize a client with your endpoint and credentials.
- Build chat messages and set generation parameters (system prompt, user messages, temperature, max_tokens, etc.).
- Send the request (sync or async).
- Process the response and integrate it into your application.
Never hardcode secrets (API keys or endpoints) in source code. Use environment variables or a secure secrets manager.
Store your Azure endpoint and API key in environment variables or a secure secrets store. Never commit keys to source control.
Python + Flask example (synchronous SDK)
Below is a compact single-file Flask app that demonstrates a typical synchronous integration using the azure.ai.openai package. It reads credentials from environment variables, initializes the OpenAIClient with AzureKeyCredential, forwards user input to a deployed model, and returns the assistant reply as JSON.
- Initialization: create an OpenAIClient using your Azure endpoint and AzureKeyCredential.
- Messages: construct a list of chat messages with roles (“system”, “user”, optionally “assistant”).
- Request: call client.get_chat_completions with your deployment_id and generation parameters (temperature, max_tokens).
- Response: extract the assistant text from response.choices[0].message.content (strip whitespace).
Response headers (example)
Request headers (example)
Next steps / integrations
- Add authentication and authorization for your Flask endpoints to protect access.
- Integrate with internal knowledge sources or a vector database to implement retrieval-augmented generation (RAG) for context-aware answers. See an intro to RAG here: Fundamentals of RAG.
- If your app needs high concurrency, switch to the async client or run the Flask app behind an async-friendly server.
- Consult Azure OpenAI docs for deployment, scaling, and best practices: https://learn.microsoft.com/azure/cognitive-services/openai/