Azure OpenAI (gateway)

To route Azure OpenAI through the Respan gateway, switch from the AzureOpenAI client to the standard OpenAI client. It is a small, mechanical change: the request and response shapes are identical (both classes live in the same openai package), so only the constructor changes.

The stock AzureOpenAI client cannot point at the Respan gateway. It always rewrites the path to .../deployments/{model}/chat/completions, which the gateway’s OpenAI-compatible router (/api/chat/completions) does not serve, so every request 404s. Use the OpenAI client instead, as shown below.

Migrate from AzureOpenAI to OpenAI

1

Install the SDK

Already installed if you use the Azure client — it is the same package.

$# Python
$pip install openai
$
$# TypeScript
$npm install openai
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export RESPAN_BASE_URL="https://api.respan.ai/api"
$export RESPAN_MODEL="YOUR_MODEL_OR_DEPLOYMENT_SLUG"

Configure your Azure OpenAI provider credentials and deployments in Respan first. Your raw Azure key stays in Respan; the app only holds RESPAN_API_KEY.

3

Swap the client

Change the constructor. Everything after it — chat.completions.create, messages, streaming, tools, response parsing — stays the same.

1from openai import AzureOpenAI
2
3client = AzureOpenAI(
4 azure_endpoint="https://YOUR_RESOURCE.openai.azure.com",
5 api_key="YOUR_AZURE_OPENAI_API_KEY",
6 api_version="2024-10-21",
7)
8
9response = client.chat.completions.create(
10 model="your-azure-deployment",
11 messages=[{"role": "user", "content": "Say hello in one sentence."}],
12)

TypeScript is the same swap:

1import { AzureOpenAI } from "openai";
2
3const client = new AzureOpenAI({
4 endpoint: "https://YOUR_RESOURCE.openai.azure.com",
5 apiKey: process.env.AZURE_OPENAI_API_KEY,
6 apiVersion: "2024-10-21",
7});

What changes

AzureOpenAI clientOpenAI client through Respan
AzureOpenAI(...)OpenAI(...)
azure_endpoint="https://….openai.azure.com"base_url="https://api.respan.ai/api"
api_key=<Azure key>api_key=<Respan key>
api_version="…"not needed — remove it
azure_deployment="…"not needed — set model per request
model="<deployment name>"model="<model or slug in Respan>"

Nothing else in your call sites changes.

Fallback to another provider

The gateway can fail over automatically. This is the common Azure-primary, Claude-fallback setup:

1response = client.chat.completions.create(
2 model=os.environ["RESPAN_MODEL"],
3 messages=[{"role": "user", "content": "Say hello in one sentence."}],
4 extra_body={"fallback_models": ["claude-sonnet-4-5-20250929"]},
5)

Switch models

Change model to another Azure deployment or to any other model configured for your Respan gateway account.

1client.chat.completions.create(model="YOUR_MODEL_OR_DEPLOYMENT_SLUG", messages=messages)
2client.chat.completions.create(model="gpt-4o-mini", messages=messages)
3client.chat.completions.create(model="claude-sonnet-4-5-20250929", messages=messages)

See the full model list.

Escape hatch: keep the AzureOpenAI client

Prefer the migration above. Use this only if you genuinely cannot change your AzureOpenAI(...) call sites. It overrides a private method of the openai SDK (_build_request / buildRequest), so it is fragile across SDK versions — pin your openai version and re-test after any major upgrade.

Subclass the Azure client to skip its /deployments/{model} path rewrite, and send auth as a bearer token (the router does not accept the Azure api-key header):

1import os
2from openai import AzureOpenAI, OpenAI
3
4class RespanAzureOpenAI(AzureOpenAI):
5 def _build_request(self, options, *, retries_taken=0):
6 return OpenAI._build_request(self, options, retries_taken=retries_taken)
7
8respan_api_key = os.environ["RESPAN_API_KEY"]
9
10client = RespanAzureOpenAI(
11 base_url=os.environ["RESPAN_BASE_URL"],
12 api_key=respan_api_key,
13 api_version="2024-10-21", # required by the client; ignored by the gateway
14 default_headers={"Authorization": f"Bearer {respan_api_key}"},
15)