The OpenAI SDK refers to the client libraries (such as the Python
openai package or JavaScript openai npm package) that connect to OpenAI v1 API endpoints. These SDKs have their own versioning separate from the API version - for example, the Go OpenAI SDK is currently at v3, but it still connects to the OpenAI v1 API endpoints with /openai/v1/ in the URL path.Benefits of migrating
Migrating to the OpenAI SDK provides several advantages:- Broader model support: Works with Azure OpenAI in Foundry Models and other Foundry Models from providers like DeepSeek and Grok
- Unified API: Uses the same SDK libraries and clients for both OpenAI and Azure OpenAI endpoints
- Latest features: Access to the newest OpenAI features without waiting for Azure-specific updates
- Simplified authentication: Built-in support for both API key and Microsoft Entra ID authentication
- Implicit API versioning: The v1 API eliminates the need to frequently update
api-versionparameters
Key differences
The following table shows the main differences between the two SDKs:| Aspect | Azure AI Inference SDK | OpenAI SDK |
|---|---|---|
| Client class | ChatCompletionsClient | OpenAI |
| Endpoint format | https://<resource>.services.ai.azure.com/models | https://<resource>.openai.azure.com/openai/v1/ |
| API version | Required in URL or parameter | Not required (uses v1 API) |
| Model parameter | Optional (for multi-model endpoints) | Required (deployment name) |
| Authentication | Azure credentials only | API key or Azure credentials |
Common migration patterns
Model parameter handling
- Azure AI Inference SDK: The
modelparameter is optional for single-model endpoints but required for multimodel endpoints. - OpenAI SDK: The
modelparameter is always required and should be set to your deployment name.
Endpoint URL format
- Azure AI Inference SDK: Uses
https://<resource>.services.ai.azure.com/models. - OpenAI SDK: Uses
https://<resource>.openai.azure.com/openai/v1(connects to the OpenAI v1 API).
Response structure
The response structure is similar but has some differences:- Azure AI Inference SDK: Returns
ChatCompletionsobject withchoices[].message.content. - OpenAI SDK: Returns
ChatCompletionobject withchoices[].message.content.
- Message content
- Token usage
- Model information
- Finish reason
Migration checklist
Use this checklist to ensure a smooth migration:- Install the OpenAI SDK for your programming language
- Update authentication code (API key or Microsoft Entra ID)
- Change endpoint URLs from
.services.ai.azure.com/modelsto.openai.azure.com/openai/v1/ - Change the credential scope from
https://cognitiveservices.azure.com/.defaulttohttps://ai.azure.com/.default - Update client initialization code
- Always specify the
modelparameter with your deployment name - Update request method calls (
complete→chat.completions.create) - Update streaming code if applicable
- Update error handling to use OpenAI SDK exceptions
- Test all functionality thoroughly
- Update documentation and code comments
Troubleshooting
Authentication failures
If you experience authentication failures:- Verify your API key is correct and isn’t expired
- For Microsoft Entra ID, ensure your application has the correct permissions
- Check that the credential scope is set to
https://ai.azure.com/.default
Endpoint errors
If you receive endpoint errors:- Verify the endpoint URL format includes
/openai/v1/at the end. - Ensure your resource name is correct.
- Check that the model deployment exists and is active.
Model not found errors
If you receive “model not found” errors:- Verify you’re using your deployment name, not the model name.
- Check that the deployment is active in your Microsoft Foundry resource.
- Ensure the deployment name matches exactly (case-sensitive).