Responses API

Use the OpenAI-compatible Responses endpoint with OpenAI, Azure OpenAI, or Perplexity Agent API.

Send OpenAI Responses-shaped requests to:

POST https://api.respan.ai/api/responses

Respan authenticates the request, routes it to the selected provider, and records the response, actual model, usage, latency, and cost.

Choose a route

RouteHeaderModel shapeRequest-scoped provider credentials
OpenAINone, or X-Respan-Route-Provider: openaiopenai/gpt-5.1 or a bare OpenAI modelExact model key with api_key
Azure OpenAIX-Respan-Route-Provider: azureazure/<deployment> is recommendedExact model key with api_key, api_base, and api_version
Perplexity Agent APIX-Respan-Route-Provider: perplexityProvider-prefixed model, preset, or modelsEmpty-string provider selector with api_key

The Perplexity route is header-only. Putting route_provider_override: perplexity in the body, respan_params, or a stored prompt does not activate it. The header value is case-insensitive and surrounding whitespace is ignored.

The Perplexity value applies only to POST /api/responses. It is ignored on Chat Completions and provider passthrough endpoints. Without the header, existing OpenAI routing is unchanged.

All routes require input. OpenAI and Azure OpenAI also require model. Perplexity may omit model only when it supplies preset or models.

OpenAI route

OpenAI is the default route. You may omit X-Respan-Route-Provider, or set it explicitly to openai.

The BYOK request below uses two keys:

  • RESPAN_API_KEY authenticates the request to Respan.
  • OPENAI_API_KEY authenticates Respan to OpenAI for this request.
1import os
2import requests
3
4model = "openai/gpt-5.1"
5
6response = requests.post(
7 "https://api.respan.ai/api/responses",
8 headers={
9 "Authorization": f"Bearer {os.environ['RESPAN_API_KEY']}",
10 "Content-Type": "application/json",
11 "X-Respan-Route-Provider": "openai",
12 },
13 json={
14 "model": model,
15 "input": "Explain why small language models are useful.",
16 "respan_params": {
17 "credential_override": {
18 model: {
19 "api_key": os.environ["OPENAI_API_KEY"],
20 }
21 }
22 },
23 },
24)
25response.raise_for_status()
26
27data = response.json()
28print(data["model"])
29print(data["output"])

Respan keeps openai/gpt-5.1 as the canonical model for credential lookup and logging, then sends the bare model name to OpenAI. The credential_override key must match the model string in the request. You can omit respan_params after configuring OpenAI under Settings → Providers, or when managed OpenAI credentials are available through Respan credits.

See OpenAI provider setup.

Azure OpenAI route

Set X-Respan-Route-Provider: azure to route the request through Azure OpenAI. Use an azure/-prefixed deployment name in both model and credential_override so the credential lookup is unambiguous.

The BYOK request requires:

  • RESPAN_API_KEY for Respan authentication.
  • AZURE_OPENAI_API_KEY for the Azure resource.
  • AZURE_OPENAI_ENDPOINT, such as https://YOUR_RESOURCE.openai.azure.com.
  • AZURE_OPENAI_API_VERSION, matching the deployment.
1import os
2import requests
3
4model = "azure/gpt-4o"
5
6response = requests.post(
7 "https://api.respan.ai/api/responses",
8 headers={
9 "Authorization": f"Bearer {os.environ['RESPAN_API_KEY']}",
10 "Content-Type": "application/json",
11 "X-Respan-Route-Provider": "azure",
12 },
13 json={
14 "model": model,
15 "input": "Summarize the benefits of retrieval-augmented generation.",
16 "respan_params": {
17 "credential_override": {
18 model: {
19 "api_key": os.environ["AZURE_OPENAI_API_KEY"],
20 "api_base": os.environ["AZURE_OPENAI_ENDPOINT"],
21 "api_version": os.environ["AZURE_OPENAI_API_VERSION"],
22 }
23 }
24 },
25 },
26)
27response.raise_for_status()
28
29data = response.json()
30print(data["model"])
31print(data["output"])

Replace gpt-4o with your Azure deployment name. Respan strips the azure/ prefix before calling the Azure SDK. You can omit respan_params after configuring an Azure OpenAI provider integration containing all three credential fields.

See Azure OpenAI provider setup.

Perplexity Agent API route

The default BYOK request uses two keys:

  • RESPAN_API_KEY authenticates the request to Respan.
  • PERPLEXITY_API_KEY is passed as a request-scoped provider credential.

You can omit the request-scoped credential after adding Perplexity under Settings → Providers, or when managed Perplexity credentials are available through Respan credits.

1import os
2import requests
3
4response = requests.post(
5 "https://api.respan.ai/api/responses",
6 headers={
7 "Authorization": f"Bearer {os.environ['RESPAN_API_KEY']}",
8 "Content-Type": "application/json",
9 "X-Respan-Route-Provider": "perplexity",
10 },
11 json={
12 "preset": "medium",
13 "input": "Summarize the latest developments in small language models.",
14 "max_steps": 1,
15 "respan_params": {
16 "credential_override": {
17 "": {
18 "api_key": os.environ["PERPLEXITY_API_KEY"],
19 }
20 }
21 },
22 },
23)
24response.raise_for_status()
25
26data = response.json()
27print(data["model"])
28print(data["output"])

The empty-string selector inside credential_override is intentional. Perplexity Agent API credentials are provider-scoped rather than tied to a single model. Never commit a real provider key; load it from an environment variable or store it in Settings → Providers.

The response model is the actual model selected by Perplexity. A preset-only request therefore does not need a model field.

Perplexity request shapes

Explicit model

Perplexity Agent API accepts provider-prefixed model names. Respan passes the name through unchanged.

1{
2 "model": "openai/gpt-5.1",
3 "input": "Compare two approaches to retrieval-augmented generation."
4}

Preset-only

Omit model and let Perplexity select one using a preset.

1{
2 "preset": "medium",
3 "input": "Research the current state of browser agents.",
4 "max_steps": 4
5}

Fallback chain

Use models to provide models in the order Perplexity should try them.

1{
2 "models": [
3 "openai/gpt-5.1",
4 "anthropic/claude-sonnet-4.5"
5 ],
6 "input": "Explain the tradeoffs of each approach."
7}

Streaming

Set stream: true to receive Responses API server-sent events. The stream ends with a response.completed event.

1{
2 "model": "openai/gpt-5.1",
3 "input": "Give me a concise research summary.",
4 "stream": true
5}

Perplexity parameters

These extensions are accepted only when the Perplexity route header is present:

ParameterTypePurpose
presetstringLet Perplexity choose the serving configuration.
modelsstring[]Ordered fallback model chain.
max_stepsintegerMaximum number of agent steps.
language_preferencestringPreferred response language.
response_formatobjectStructured response configuration.
skillsarrayPerplexity Agent API skills.
toolsarrayTools available to the agent, including web search.

Perplexity-only parameters are discarded on non-Perplexity routes.

Web search filters

1{
2 "preset": "medium",
3 "input": "Find the latest Respan documentation updates.",
4 "tools": [
5 {
6 "type": "web_search",
7 "filters": {
8 "search_domain_filter": ["respan.ai"]
9 }
10 }
11 ]
12}

Perplexity credentials

Per-request BYOK

Pass the Perplexity key under the provider-scoped empty-string selector:

1{
2 "respan_params": {
3 "credential_override": {
4 "": {
5 "api_key": "YOUR_PERPLEXITY_API_KEY"
6 }
7 }
8 }
9}

The Respan API key still belongs in Authorization: Bearer YOUR_RESPAN_API_KEY; it is not replaced by the Perplexity key.

Stored or managed credentials

Alternatively, add a Perplexity provider integration with an api_key. The credential is provider-scoped: an older integration’s Sonar available_models list does not restrict Agent API model or preset requests. Managed Perplexity credentials can be used when available through Respan credits.

If neither a customer-owned nor a managed Perplexity credential is available, the endpoint returns 401 and asks you to add a Perplexity API key.

See Perplexity provider setup.

Logging and billing

Every successful route returns X-Respan-Log-Id.

RouteLogged provider/model behavior
OpenAILogs the canonical OpenAI model and standard gateway usage/cost.
Azure OpenAILogs the resolved azure/<deployment> model and Azure usage/cost.
PerplexityLogs provider_id: perplexity, the actual model returned by Perplexity, and provider-reported cost when present.

Perplexity cost details

For Perplexity, Respan logs:

  • provider_id: perplexity
  • the actual model returned by Perplexity
  • provider-reported USD cost when present
  • input, output, cache-read, cache-creation, and tool-call cost components

Perplexity’s reported usage.cost.total_cost is authoritative for logging and credit deduction. If the component values do not reconcile with the total, Respan records the difference under provider_reported. Missing or invalid cost data falls back to catalog token-pricing estimates.

Troubleshooting

SymptomFix
OpenAI or Azure request fails before reaching the providerInclude both required input and model fields.
401 asks for an OpenAI keyAdd an OpenAI provider integration or supply an exact-model credential_override.
Azure reports missing credential fieldsSupply api_key, api_base, and api_version, or update the stored Azure integration.
Azure cannot find the deploymentConfirm the value after azure/ matches the deployment name and that api_base points to the correct Azure resource.
Request follows the OpenAI routeAdd X-Respan-Route-Provider: perplexity; a body field alone is ignored.
401 asks for a Perplexity keyAdd a Perplexity provider integration or enable managed Perplexity credentials.
Perplexity-only fields disappearConfirm the header is present on POST /api/responses, not Chat Completions.
Preset-only failure log shows perplexity/agentThis sentinel is used only when Perplexity did not return an actual model.

See Create response for the endpoint reference, or open the OpenAI, Azure OpenAI, and Perplexity provider setup guides.