Ir al contenido

API de relay: chat

Esta página se genera a partir de docs-site/openapi/relay.yaml. Su contenido está en inglés; no la edites a mano.

Text generation in four dialects.

OpenAI Chat Completions

operationId relayChatCompletions · auth: bearerAuth

Streaming ("stream": true) answers with text/event-stream and always ends with a chunk that carries usage (including usage.cost), then data: [DONE], whether or not the client sets stream_options.include_usage.

Request body (required) application/json — ChatCompletionRequest

  • provider (RoutingPreferences) — Per-request routing wishes (OpenRouter-style). Use only the keys listed here: the Anthropic and Gemini dialects reject unknown keys with 400, and the others may ignore them. See docs/routing for the exact ranking.
    • order (array of string) — Provider tags to try first, in this order. Matching is case-insensitive.
    • only (array of string) — Use only these providers. 400 provider_not_found when none of them offers the model.
    • ignore (array of string) — Never use these providers.
    • sort (“price” | “latency” | “throughput”) — Rank the providers that are not named in order. Providers with no measurement yet rank last.
    • allow_fallbacks (boolean) — false together with order (or a model:provider pin) restricts routing to those providers. Without order or a pin it has no effect.
  • models (array of string) — Fallback list. The first entry that differs from model is tried after every provider of model has failed before the response started. One fallback model is used; further entries are ignored. The fallback is billed at its own price.
  • usage (UsageSwitch) — Accepted and removed before the request reaches the provider. The cost is always returned; the switch exists so that clients written for other gateways keep working.
    • include (boolean)
  • model (string, required) — A model slug or alias, optionally followed by :<provider tag>.
  • messages (array of object, required)
  • stream (boolean)
  • max_tokens (integer)
  • max_completion_tokens (integer)
Status Meaning Body
200 A completion, or an SSE stream of chunks. application/json OpenAIObject, text/event-stream string
default Error in the OpenAI envelope (error.message, error.type, error.param, error.code). application/json OpenAIError

Response 200 application/json — OpenAIObject

The provider-shaped response object of the dialect, with cost added inside its usage object.

Response 200 text/event-stream — string

OpenAI Responses

operationId relayResponses · auth: bearerAuth

"background": true is rejected (400, param background): the gateway bills from the response it relays. A previous_response_id is only accepted for a response that your organisation created through the gateway (otherwise 404 previous_response_not_found), and the follow-up request is routed to the same provider and upstream key.

Request body (required) application/json — ResponsesRequest

  • provider (RoutingPreferences) — Per-request routing wishes (OpenRouter-style). Use only the keys listed here: the Anthropic and Gemini dialects reject unknown keys with 400, and the others may ignore them. See docs/routing for the exact ranking.
    • order (array of string) — Provider tags to try first, in this order. Matching is case-insensitive.
    • only (array of string) — Use only these providers. 400 provider_not_found when none of them offers the model.
    • ignore (array of string) — Never use these providers.
    • sort (“price” | “latency” | “throughput”) — Rank the providers that are not named in order. Providers with no measurement yet rank last.
    • allow_fallbacks (boolean) — false together with order (or a model:provider pin) restricts routing to those providers. Without order or a pin it has no effect.
  • models (array of string) — Fallback list. The first entry that differs from model is tried after every provider of model has failed before the response started. One fallback model is used; further entries are ignored. The fallback is billed at its own price.
  • usage (UsageSwitch) — Accepted and removed before the request reaches the provider. The cost is always returned; the switch exists so that clients written for other gateways keep working.
    • include (boolean)
  • model (string, required)
  • input (any)
  • stream (boolean)
  • previous_response_id (string)
Status Meaning Body
200 A response object, or an SSE stream of Responses events. application/json OpenAIObject, text/event-stream string
default Error in the OpenAI envelope (error.message, error.type, error.param, error.code). application/json OpenAIError

Response 200 application/json — OpenAIObject

The provider-shaped response object of the dialect, with cost added inside its usage object.

Response 200 text/event-stream — string

Anthropic Messages

operationId relayMessages · auth: apiKeyHeader or bearerAuth

max_tokens is required, as at Anthropic. Errors use Anthropic’s envelope ({"type":"error","error":{...}}); insufficient balance is billing_error with HTTP 402, an overloaded upstream is HTTP 529. There is no /v1/messages/count_tokens route.

Request body (required) application/json — MessagesRequest

  • provider (RoutingPreferences) — Per-request routing wishes (OpenRouter-style). Use only the keys listed here: the Anthropic and Gemini dialects reject unknown keys with 400, and the others may ignore them. See docs/routing for the exact ranking.
    • order (array of string) — Provider tags to try first, in this order. Matching is case-insensitive.
    • only (array of string) — Use only these providers. 400 provider_not_found when none of them offers the model.
    • ignore (array of string) — Never use these providers.
    • sort (“price” | “latency” | “throughput”) — Rank the providers that are not named in order. Providers with no measurement yet rank last.
    • allow_fallbacks (boolean) — false together with order (or a model:provider pin) restricts routing to those providers. Without order or a pin it has no effect.
  • models (array of string) — Fallback list. The first entry that differs from model is tried after every provider of model has failed before the response started. One fallback model is used; further entries are ignored. The fallback is billed at its own price.
  • usage (UsageSwitch) — Accepted and removed before the request reaches the provider. The cost is always returned; the switch exists so that clients written for other gateways keep working.
    • include (boolean)
  • model (string) — Required unless models is given, in which case its first entry is the model.
  • max_tokens (integer, required, minimum: 1)
  • messages (array of object, required)
  • stream (boolean)
Status Meaning Body
200 A message, or an SSE stream of Anthropic events. application/json OpenAIObject, text/event-stream string
default Error in the Anthropic envelope. application/json AnthropicError

Response 200 application/json — OpenAIObject

The provider-shaped response object of the dialect, with cost added inside its usage object.

Response 200 text/event-stream — string

Gemini generateContent

operationId relayGenerateContent · auth: googApiKeyHeader or googApiKeyQuery or bearerAuth

Parameter In Type Required Description
model path string yes The model, directly followed by the :method of the route. The gateway splits at the last colon, so gpt-4o-mini:azure:generateContent calls gpt-4o-mini pinned to the provider tagged azure.

Request body (required) application/json — GenerateContentRequest

  • provider (RoutingPreferences) — Per-request routing wishes (OpenRouter-style). Use only the keys listed here: the Anthropic and Gemini dialects reject unknown keys with 400, and the others may ignore them. See docs/routing for the exact ranking.
    • order (array of string) — Provider tags to try first, in this order. Matching is case-insensitive.
    • only (array of string) — Use only these providers. 400 provider_not_found when none of them offers the model.
    • ignore (array of string) — Never use these providers.
    • sort (“price” | “latency” | “throughput”) — Rank the providers that are not named in order. Providers with no measurement yet rank last.
    • allow_fallbacks (boolean) — false together with order (or a model:provider pin) restricts routing to those providers. Without order or a pin it has no effect.
  • models (array of string) — Fallback list. The first entry that differs from model is tried after every provider of model has failed before the response started. One fallback model is used; further entries are ignored. The fallback is billed at its own price.
  • usage (UsageSwitch) — Accepted and removed before the request reaches the provider. The cost is always returned; the switch exists so that clients written for other gateways keep working.
    • include (boolean)
  • contents (array of object, required)
Status Meaning Body
200 A GenerateContentResponse with usageMetadata.cost added. application/json OpenAIObject
default Error in the Google envelope (error.code, error.message, error.status). application/json GeminiError

Response 200 application/json — OpenAIObject

The provider-shaped response object of the dialect, with cost added inside its usage object.

POST /v1beta/models/{model}:streamGenerateContent

Sección titulada «POST /v1beta/models/{model}:streamGenerateContent»

Gemini streamGenerateContent

operationId relayStreamGenerateContent · auth: googApiKeyHeader or googApiKeyQuery or bearerAuth

Without alt=sse the stream is one JSON array of GenerateContentResponse objects; with ?alt=sse it is text/event-stream.

Parameter In Type Required Description
model path string yes The model, directly followed by the :method of the route. The gateway splits at the last colon, so gpt-4o-mini:azure:generateContent calls gpt-4o-mini pinned to the provider tagged azure.
alt query “sse” no

Request body (required) application/json — GenerateContentRequest

  • provider (RoutingPreferences) — Per-request routing wishes (OpenRouter-style). Use only the keys listed here: the Anthropic and Gemini dialects reject unknown keys with 400, and the others may ignore them. See docs/routing for the exact ranking.
    • order (array of string) — Provider tags to try first, in this order. Matching is case-insensitive.
    • only (array of string) — Use only these providers. 400 provider_not_found when none of them offers the model.
    • ignore (array of string) — Never use these providers.
    • sort (“price” | “latency” | “throughput”) — Rank the providers that are not named in order. Providers with no measurement yet rank last.
    • allow_fallbacks (boolean) — false together with order (or a model:provider pin) restricts routing to those providers. Without order or a pin it has no effect.
  • models (array of string) — Fallback list. The first entry that differs from model is tried after every provider of model has failed before the response started. One fallback model is used; further entries are ignored. The fallback is billed at its own price.
  • usage (UsageSwitch) — Accepted and removed before the request reaches the provider. The cost is always returned; the switch exists so that clients written for other gateways keep working.
    • include (boolean)
  • contents (array of object, required)
Status Meaning Body
200 A stream of GenerateContentResponse objects. application/json array of OpenAIObject, text/event-stream string
default Error in the Google envelope (error.code, error.message, error.status). application/json GeminiError

Response 200 application/json — array of OpenAIObject

Response 200 text/event-stream — string