Azure OpenAI supported programming languages
This article refers to the Microsoft Foundry (new) portal.
Prerequisites
- An Azue OpenAI model deployed
- One of the following authentication methods:
- Microsoft Entra ID (recommended).
- An API key.
Azure OpenAI API version support
- v1 Generally Available (GA) API now allows access to both GA and Preview operations. To learn more, see the API version lifecycle guide.
Installation
Authentication
- Microsoft Entra ID
- API Key
A secure, keyless authentication approach is to use Microsoft Entra ID (formerly Azure Active Directory) via the Azure Identity library. To use the library:Use the desired credential type from the library. For example, For more information about Azure OpenAI keyless authentication, see the “Get started with the Azure OpenAI security building block” QuickStart article.
DefaultAzureCredential:Chat
Example of chat completions request to a reasoning model.Embeddings
Responses API
Streaming
MCP Server
Error handling
Error codes
| Status Code | Error Type |
|---|---|
| 400 | Bad Request Error |
| 401 | Authentication Error |
| 403 | Permission Denied Error |
| 404 | Not Found Error |
| 422 | Unprocessable Entity Error |
| 429 | Rate Limit Error |
| 500 | Internal Server Error |
| 503 | Service Unavailable |
| 504 | Gateway Timeout |
Retries
The client classes will automatically retry the following errors up to three more times using exponential backoff:- 408 Request Timeout
- 429 Too Many Requests
- 500 Internal Server Error
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
Azure OpenAI API version support
- v1 Generally Available (GA) API now allows access to both GA and Preview operations. To learn more, see the API version lifecycle guide.
Installation
Install theopenai and azidentity modules with go get:
Authentication
- Microsoft Entra ID
- API Key
The azidentity module is used for Microsoft Entra ID authentication with Azure OpenAI.For more information about Azure OpenAI keyless authentication, see Use Azure OpenAI without keys.
Embeddings
Responses
Azure OpenAI API version support
- v1 Generally Available (GA) API now allows access to both GA and Preview operations. To learn more, see the API version lifecycle guide.
Installation
Gradle
Maven
Authentication
- Microsoft Entra ID
- API Key
Authentication with Microsoft Entra ID requires some initial setup:Add the Azure Identity package:After setup, you can choose which type of credential from For more information about Azure OpenAI keyless authentication, see Use Azure OpenAI without keys.
azure.identity to use. As an example, DefaultAzureCredential can be used to authenticate the client: Set the values of the client ID, tenant ID, and client secret of the Microsoft Entra ID application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.Authorization is easiest using DefaultAzureCredential. It finds the best credential to use in its running environment though use of DefaultAzureCredential is only recommended for testing, not for production.Responses
Azure OpenAI API version support
- v1 Generally Available (GA) API now allows access to both GA and Preview operations. To learn more, see the API version lifecycle guide.
Installation
Authentication
- Microsoft Entra ID
- API Key
OpenAI client, however, we need to use the getBearerTokenProvider function from the @azure/identity package. This function creates a token provider that OpenAI uses internally to obtain tokens for each request. The token provider is created as follows:Responses
responses.create
Streaming
MCP Server
Chat
chat.completions.create
Error handling
Error codes
| Status Code | Error Type |
|---|---|
| 400 | Bad Request Error |
| 401 | Authentication Error |
| 403 | Permission Denied Error |
| 404 | Not Found Error |
| 422 | Unprocessable Entity Error |
| 429 | Rate Limit Error |
| 500 | Internal Server Error |
| 503 | Service Unavailable |
| 504 | Gateway Timeout |
Retries
The following errors are automatically retried twice by default with a brief exponential backoff:- Connection Errors
- 408 Request Timeout
- 429 Rate Limit
>=500 Internal Errors
maxRetries to set/disable the retry behavior:
This library is maintained by OpenAI. Refer to the release history to track the latest updates to the library.
Azure OpenAI API version support
- v1 Generally Available (GA) API now allows access to both GA and Preview operations. To learn more, see the API version lifecycle guide.
Installation
Authentication
Endpoints and API keys for your resources can be retrieved from the Azure portal or the Microsoft Foundry portal:- Sign in to Azure portal > select your resource > Resource Management > Keys and Endpoint.
- Sign in to Microsoft Foundry portal > select your resource.
- Microsoft Entra ID
- API Key
- Environment Variables
- Response
Responses API
responses.create()
- Microsoft Entra ID
- API Key
- Environment Variables
- Response
responses.create() with MCP server tool
- Microsoft Entra ID
- API Key
- Environment Variables
- Response
Chat
chat.completions.create()
chat.completions.create() - streaming
chat.completions.create() - image input
Embeddings
embeddings.create()
- Microsoft Entra ID
- API Key
- Environment Variables
- Response
Embeddings currently don’t support Microsoft Entra ID with Azure OpenAI and the v1 API.
Fine-tuning
Fine-tuning with Python how-to articleError handling
Error codes
| Status Code | Error Type |
|---|---|
| 400 | BadRequestError |
| 401 | AuthenticationError |
| 403 | PermissionDeniedError |
| 404 | NotFoundError |
| 422 | UnprocessableEntityError |
| 429 | RateLimitError |
| >=500 | InternalServerError |
| N/A | APIConnectionError |
Request IDs
To retrieve the ID of your request, you can use the_request_id property, which corresponds to the x-request-id response header.
Retries
The following errors are automatically retired twice by default with a brief exponential backoff:- Connection Errors
- 408 Request Timeout
- 429 Rate Limit
>=500 Internal Errors
max_retries to set/disable the retry behavior:
Troubleshooting
- If you get a
401or403error, confirm you authenticated with the intended identity or key, and that it has access to the Azure OpenAI resource. - If you get a
404error, confirm the endpoint uses the...openai.azure.com/openai/v1/path and that you used a valid model deployment name. - If requests fail unexpectedly, check for proxy and firewall restrictions, and retry with a smaller prompt to rule out payload-size issues.