Azure OpenAI vs OpenAI API: 6 Differences, with SDK Switch Code

Blog / Relays & gateways

Azure OpenAI vs OpenAI API: 6 Differences, with SDK Switch Code

Azure OpenAI and the OpenAI API give you the same family of model capabilities. The real difference is who your provider is. The former is a Microsoft Azure cloud service, so account, billing, compliance, and networking all sit under Azure. The latter is OpenAI's own platform, where the account and invoices belong to OpenAI. At the code level the request formats are broadly similar, but the endpoint, authentication method, and the meaning of "model name" differ. Those are the places you need to change when switching.

If you are searching for the difference between Azure OpenAI and OpenAI, you are usually doing one of two things: choosing an entry point that meets your company's compliance requirements, or migrating existing OpenAI code to Azure. This article covers both. Features and limits described here are subject to the official Microsoft and OpenAI documentation, which changes quickly.

The models are developed by OpenAI. Azure OpenAI is Microsoft hosting and selling those models as an Azure service. So it is not a different model, it is a different entry point. On Azure you create an Azure resource, governed by your Azure subscription, its permission system (Entra ID, RBAC), and your enterprise agreement. On the OpenAI platform you create an organization and projects, governed by OpenAI's usage policies.

New-model release timing, available features, and selectable regions are not always in sync between the two. Check the relevant official model pages when choosing, and do not rely on impressions.

Comparison table: 6 dimensions

DimensionOpenAI APIAzure OpenAI
Account ownerOpenAI organization and projectsA resource under an Azure subscription
BillingOpenAI invoice, prepaid or pay by usageFolded into your Azure bill; enterprise agreements can apply
Content filteringUsage policies and moderation mechanismsBuilt-in content filtering, configurable per resource; for adjusting rules, follow Microsoft's official docs
Data residencyPer OpenAI's data control optionsSelectable region, data zone, or global deployment types; see the official docs
EndpointA fixed OpenAI API domainEach resource has its own endpoint
Specifying the modelYou put the model name in the requestYou put the "deployment name" in the request (the name you chose when creating the deployment)

A few notes:

  • The account owner decides who handles bans, appeals, and contract issues. On Azure you deal with Azure support and compliance processes. On the OpenAI platform you deal with OpenAI's policies. For the official rules on restricted accounts, see OpenAI usage policies explained.
  • The ChatGPT subscription and the pay-as-you-go API are two separate billing systems. That is covered in ChatGPT Plus vs the OpenAI API. Azure OpenAI is likewise unrelated to a ChatGPT subscription.
  • The OpenAI platform has a list of supported countries and regions; see Which countries and regions does OpenAI support. Azure region availability depends on Azure's own region and model availability lists. Follow each service's terms and local regulations.

What are the advantages of Azure OpenAI?

The commonly cited Azure OpenAI advantages are concentrated in enterprise scenarios:

  1. Unified billing and permissions: it sits alongside your existing Azure subscription, cost management, and role permissions, a process your finance and security teams already know.
  2. More authentication options: besides API keys, it supports Microsoft Entra ID authentication, so you can avoid keeping long-lived secrets in code.
  3. Network and data control: you can combine Azure networking features and region selection to meet internal requirements. Check the official docs for what is supported.
  4. Configurable content filtering: for products that need a moderation policy, the filtering rules are a resource-level setting.

Know the costs up front too: access may require approval, deployments require choosing a region and deployment type first, quota is allocated per deployment and region, and new models may become available at a different time than on the OpenAI platform. For the application process, see How to apply for Azure OpenAI.

How should an individual developer or small team choose?

Use this checklist:

  • Your company already uses Azure and requires data, billing, and permissions to stay inside the cloud vendor: choose Azure OpenAI.
  • You are building a prototype or personal project and want a key as fast as possible: the OpenAI platform is more direct.
  • You need models from several vendors at once: no single provider covers that. You can look into aggregation gateways, but vet them first; see Are third-party AI gateways reliable?

How do you switch the endpoint and SDK?

The Azure OpenAI endpoint has one address per resource, usually of the form https://<your-resource-name>.openai.azure.com, which you can find on the resource page in the Azure portal. Besides a key, you can also authenticate with Entra ID. The api-version parameter has different requirements depending on the API style; follow the official docs.

Below is the most common Azure OpenAI SDK usage, using the official Python package openai as the example.

Calling the OpenAI platform:

from openai import OpenAI

client = OpenAI(api_key="sk-...")
resp = client.chat.completions.create(
    model="<OpenAI model name>",
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)

Calling Azure OpenAI:

from openai import AzureOpenAI

client = AzureOpenAI(
    azure_endpoint="https://<your-resource-name>.openai.azure.com",
    api_key="<Azure resource key>",
    api_version="<see official docs>",
)
resp = client.chat.completions.create(
    model="<your deployment name>",   # Put the deployment name here, not the model name
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)

The most common mistake is the model field. On Azure it takes the name you gave the deployment when you created it. If the deployment name differs from the model name, passing the model name directly will fail with a "deployment not found" error.

Migration checklist

Before migrating from OpenAI to Azure, confirm each item:

  1. You have created a resource in the target region and created a deployment for each model you need. Note the deployment names.
  2. The code uses the Azure client or endpoint, and model is set to the deployment name.
  3. You have confirmed the api-version or the API style you use, per the official docs.
  4. You have checked whether the content filtering policy will block your existing prompts. Run a set of typical requests in a test environment.
  5. You have rechecked rate limits and quota. Azure quota is allocated per deployment, so read the Azure docs for what a 429 means. For how OpenAI platform 429s are distinguished, see insufficient_quota vs rate_limit_exceeded.
  6. You have reviewed timeout and retry settings; see OpenAI SDK timeout and retry configuration.
  7. If you use keys, store and rotate them properly. For what to do after a leak, see Your OpenAI API key leaked.

How do you evaluate latency and availability?

Different entry points and regions have different network paths, so measure actual latency yourself. You can use cdnping's online speed test to measure first-connection time and round trip from your current network to model APIs such as OpenAI, and the API status page to see probe records for the official entry points. For the underlying principles, see AI API latency and access from China. Note that cdnping tests the official public entry points only. It does not include your private Azure resource address, so use your own monitoring for how your Azure resource performs.

If you just want to use Claude Code or Codex

Some readers look into Azure only to get a tool like Codex running. Such tools usually need only an endpoint plus a key. AGI Plan is a multi-provider LLM aggregation gateway. It is billed as a monthly subscription, paid in RMB with no overseas credit card needed, and it is compatible with both the OpenAI and Anthropic API formats. Claude Code and Codex work after changing a single endpoint, and one subscription can be switched across several capability groups. Some models are marked as available outside China only; check the AGI Plan models page. The service also states plainly that it is not an officially authorized channel. AGI Plan is a commercial partner of cdnping. To learn how to connect, see the getting started guide; for tool-side configuration, see Custom API endpoints for Claude Code, Codex, and OpenCode.

Next steps

  • Your company needs compliance, with billing and permissions under the cloud vendor: read How to apply for Azure OpenAI first to confirm whether you can get access.
  • You are an individual or small team that wants to get something running first: get a key from the OpenAI platform, verify with the code above, then decide whether to migrate.
  • You want to change as little code as possible: put the endpoint and the model name or deployment name in a config file or environment variables, so switching later only means changing configuration.

Related articles

Keep reading