Skip to Content

Create an OpenRouter chat completion

POSThttps://api.respan.ai/api/openrouter/v1/chat/completions

Forward OpenRouter requests and return its response, status code, or event stream unchanged. OpenRouter fields such as provider and reasoning are preserved. Supply your Respan key in Authorization and your OpenRouter key in x-openrouter-api-key; this endpoint requires your own OpenRouter key and does not use Respan gateway credits.

Servers

https://api.respan.ai: Respan API Server

Authentication

RespanApiKey

Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer <RESPAN_API_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan_params.credential_override in the request body, not in this authentication field.

HTTP scheme: bearer; format: Respan API key.

HTTP
Authorization: Bearer $RESPAN_API_KEY

Headers

Parameter Type Required Description and constraints
x-openrouter-api-key string Required
Your OpenRouter API key. Authorization carries the Respan API key on this operation.

Request body

A request body is required.

application/json

Field Type Requirement Description and constraints
$ object Required body
Additional properties are allowed
model string Required in parent
OpenRouter model slug, for example openai/gpt-6-luna. An openrouter/ prefix is also accepted and is stripped before the call goes upstream.
messages array<object> Required in parent
Minimum items: 1
messages[] object Array item
Additional properties are allowed
stream boolean Optional
Default: false
provider object Optional
OpenRouter provider routing block, forwarded unchanged.
Additional properties are allowed
reasoning object Optional
OpenRouter reasoning block, forwarded unchanged.
Additional properties are allowed
respan_params object Optional
Respan gateway metadata. Stripped before the payload reaches OpenRouter. Must be a JSON object: a string, list, number or boolean is ignored and none of its params apply.
Additional properties are allowed

OpenAPI request schema

{
  "type": "object",
  "required": [
    "model",
    "messages"
  ],
  "properties": {
    "model": {
      "type": "string",
      "description": "OpenRouter model slug, for example openai/gpt-6-luna. An openrouter/ prefix is also accepted and is stripped before the call goes upstream."
    },
    "messages": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": true
      }
    },
    "stream": {
      "type": "boolean",
      "default": false
    },
    "provider": {
      "type": "object",
      "additionalProperties": true,
      "description": "OpenRouter provider routing block, forwarded unchanged."
    },
    "reasoning": {
      "type": "object",
      "additionalProperties": true,
      "description": "OpenRouter reasoning block, forwarded unchanged."
    },
    "respan_params": {
      "type": "object",
      "additionalProperties": true,
      "description": "Respan gateway metadata. Stripped before the payload reaches OpenRouter. Must be a JSON object: a string, list, number or boolean is ignored and none of its params apply."
    }
  },
  "additionalProperties": true
}
Example
JSON
{ "model": "openai/gpt-6-luna", "messages": [ { "role": "user", "content": "Reply with exactly ok." } ], "max_tokens": 32 }

Responses

200

OpenRouter response or event stream.

application/json

Field Type Requirement Description and constraints
$ object Body
Additional properties are allowed

OpenAPI response schema

{
  "type": "object",
  "additionalProperties": true
}

text/event-stream

Field Type Requirement Description and constraints
$ string Body
OpenRouter server-sent event stream, including the data: [DONE] sentinel.

OpenAPI response schema

{
  "type": "string",
  "description": "OpenRouter server-sent event stream, including the data: [DONE] sentinel."
}

400

x-openrouter-api-key is missing, or OpenRouter rejected the request. OpenRouter’s own errors come back with its body.

application/json

Field Type Requirement Description and constraints
$ object Body
Additional properties are allowed

OpenAPI response schema

{
  "type": "object",
  "additionalProperties": true
}
Example
JSON
{ "detail": "Missing OpenRouter credentials. Send your OpenRouter API key in the 'x-openrouter-api-key' header. The 'Authorization' header carries your Respan key on this endpoint." }

402

Relayed from OpenRouter: insufficient credits.

application/json

Field Type Requirement Description and constraints
$ object Body
Additional properties are allowed

OpenAPI response schema

{
  "type": "object",
  "additionalProperties": true
}

403

The API key is missing, invalid or expired.

application/json

Field Type Requirement Description and constraints
$ object Body
-
detail string Required in parent
-

OpenAPI response schema

{
  "type": "object",
  "required": [
    "detail"
  ],
  "properties": {
    "detail": {
      "type": "string"
    }
  }
}
Example
JSON
{ "detail": "Your API key is invalid or expired, please check your API key in the platform settings." }

404

Relayed from OpenRouter: unknown model or route.

application/json

Field Type Requirement Description and constraints
$ object Body
Additional properties are allowed

OpenAPI response schema

{
  "type": "object",
  "additionalProperties": true
}

429

Rate limit exceeded, from Respan or relayed from OpenRouter.

application/json

Field Type Requirement Description and constraints
$ object Body
Additional properties are allowed

OpenAPI response schema

{
  "type": "object",
  "additionalProperties": true
}

OpenAPI source

The operation and referenced components below retain the complete OpenAPI definitions, including constraints and examples.

OpenAPI operation

{
  "summary": "Create an OpenRouter chat completion",
  "operationId": "openrouter_native_chat_completions",
  "tags": [
    "OpenRouter Gateway"
  ],
  "description": "Forward OpenRouter requests and return its response, status code, or event stream unchanged. OpenRouter fields such as `provider` and `reasoning` are preserved. Supply your Respan key in `Authorization` and your OpenRouter key in `x-openrouter-api-key`; this endpoint requires your own OpenRouter key and does not use Respan gateway credits.",
  "parameters": [
    {
      "name": "x-openrouter-api-key",
      "in": "header",
      "required": true,
      "schema": {
        "type": "string"
      },
      "description": "Your OpenRouter API key. Authorization carries the Respan API key on this operation."
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "model",
            "messages"
          ],
          "properties": {
            "model": {
              "type": "string",
              "description": "OpenRouter model slug, for example openai/gpt-6-luna. An openrouter/ prefix is also accepted and is stripped before the call goes upstream."
            },
            "messages": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "additionalProperties": true
              }
            },
            "stream": {
              "type": "boolean",
              "default": false
            },
            "provider": {
              "type": "object",
              "additionalProperties": true,
              "description": "OpenRouter provider routing block, forwarded unchanged."
            },
            "reasoning": {
              "type": "object",
              "additionalProperties": true,
              "description": "OpenRouter reasoning block, forwarded unchanged."
            },
            "respan_params": {
              "type": "object",
              "additionalProperties": true,
              "description": "Respan gateway metadata. Stripped before the payload reaches OpenRouter. Must be a JSON object: a string, list, number or boolean is ignored and none of its params apply."
            }
          },
          "additionalProperties": true
        },
        "example": {
          "model": "openai/gpt-6-luna",
          "messages": [
            {
              "role": "user",
              "content": "Reply with exactly ok."
            }
          ],
          "max_tokens": 32
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "OpenRouter response or event stream.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "text/event-stream": {
          "schema": {
            "type": "string",
            "description": "OpenRouter server-sent event stream, including the data: [DONE] sentinel."
          }
        }
      }
    },
    "400": {
      "description": "`x-openrouter-api-key` is missing, or OpenRouter rejected the request. OpenRouter's own errors come back with its body.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "additionalProperties": true
          },
          "example": {
            "detail": "Missing OpenRouter credentials. Send your OpenRouter API key in the 'x-openrouter-api-key' header. The 'Authorization' header carries your Respan key on this endpoint."
          }
        }
      }
    },
    "402": {
      "description": "Relayed from OpenRouter: insufficient credits.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    },
    "403": {
      "$ref": "#/components/responses/InvalidApiKey"
    },
    "404": {
      "description": "Relayed from OpenRouter: unknown model or route.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    },
    "429": {
      "description": "Rate limit exceeded, from Respan or relayed from OpenRouter.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    }
  },
  "security": [
    {
      "RespanApiKey": []
    }
  ]
}

OpenAPI path metadata

{}

Referenced OpenAPI components

{
  "responses": {
    "InvalidApiKey": {
      "description": "The API key is missing, invalid or expired.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "detail"
            ],
            "properties": {
              "detail": {
                "type": "string"
              }
            }
          },
          "example": {
            "detail": "Your API key is invalid or expired, please check your API key in the platform settings."
          }
        }
      }
    }
  },
  "securitySchemes": {
    "RespanApiKey": {
      "type": "http",
      "scheme": "bearer",
      "bearerFormat": "Respan API key",
      "description": "Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer <RESPAN_API_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan_params.credential_override in the request body, not in this authentication field.",
      "x-fern-bearer": {
        "name": "respanApiKey",
        "env": "RESPAN_API_KEY"
      }
    }
  }
}