plaingateway
API reference

Chat completions

Create a chat completion or stream.

POST /chat/completions takes model and messages, and the optional fields in the table below. A string prompt is also accepted in place of messages. The answer keeps the OpenAI shape. plaingateway adds usage.cost, the charge in USD. Any field the gateway does not read, such as temperature, goes to the host unchanged.

Streaming

With "stream": true the answer is server-sent events, ending with data: [DONE]. While the host has not answered yet, the gateway sends : PLAINGATEWAY PROCESSING comment lines every 15 seconds so proxies keep the connection open. Ignore lines that start with :. The final usage chunk carries usage with cost, the charge in USD. A non-streamed answer also has the X-PG-Cost-USD header. A failure after the stream started arrives as a last event with an error object; see Errors.

sh
curl -N https://api.plaingateway.com/api/v1/chat/completions \
  -H "Authorization: Bearer $PLAINGATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/gpt-5.6-luna", "messages": [{"role": "user", "content": "Count to three."}], "stream": true}'

Example

Request

sh
curl https://api.plaingateway.com/api/v1/chat/completions \
  -H "Authorization: Bearer $PLAINGATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "openai/gpt-5.6-luna",
  "messages": [
    {
      "role": "user",
      "content": "Say hello in five words."
    }
  ],
  "max_tokens": 32
}'

Response

http
HTTP/1.1 200
{
  "id": "gen-6f2d0c5e9a1b4c7d8e3f2a10",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "openai/gpt-5.6-luna",
  "provider": "OpenAI",
  "system_fingerprint": null,
  "service_tier": "default",
  "choices": [
    {
      "index": 0,
      "logprobs": null,
      "finish_reason": "stop",
      "native_finish_reason": "completed",
      "message": {
        "role": "assistant",
        "content": "Hello! How are you today?",
        "refusal": null,
        "reasoning": null
      }
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 11,
    "total_tokens": 23,
    "cost": 1.56e-05,
    "is_byok": false,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "cache_write_tokens": 0,
      "audio_tokens": 0,
      "video_tokens": 0
    },
    "cost_details": {
      "upstream_inference_cost": 1.56e-05,
      "upstream_inference_prompt_cost": 2.4e-06,
      "upstream_inference_completions_cost": 1.32e-05
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "image_tokens": 0,
      "audio_tokens": 0
    }
  }
}

Tool calling

Send tools. When the model calls one, the answer has finish_reason: "tool_calls" and the call in choices[0].message.tool_calls. Tool calling shows how to send the result back.

sh
curl https://api.plaingateway.com/api/v1/chat/completions \
  -H "Authorization: Bearer $PLAINGATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "openai/gpt-5.6-luna",
  "messages": [{"role": "user", "content": "Weather in Paris?"}],
  "tools": [{"type": "function", "function": {"name": "get_weather", "description": "Current weather for a city", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}],
  "max_tokens": 64
}'

JSON mode

Send response_format with a json_schema. The answer text in choices[0].message.content is JSON that matches the schema. Structured outputs has the details.

sh
curl https://api.plaingateway.com/api/v1/chat/completions \
  -H "Authorization: Bearer $PLAINGATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "openai/gpt-5.6-luna",
  "messages": [{"role": "user", "content": "Name a city and its country."}],
  "response_format": {"type": "json_schema", "json_schema": {"name": "place", "strict": true, "schema": {"type": "object", "properties": {"city": {"type": "string"}, "country": {"type": "string"}}, "required": ["city", "country"], "additionalProperties": false}}},
  "max_tokens": 64
}'

OpenRouter-compatible request fields

Parameter Type Semantics
model string Primary model ID.
models string[] Fallback model IDs after model, or the only IDs if model is absent.
messages object[] Conversation turns for chat or Messages.
prompt string Accepted in place of messages.
max_tokens integer Most output tokens. The balance hold is sized from it.
user string Your end user's id; stored as external_user on the generation.
stream boolean Return server-sent events.
tools object[] Available function tools.
tool_choice string or object Select tool use.
response_format object Request a structured output format.
reasoning object effort, max_tokens, and exclude reasoning controls.
usage.include boolean Ask for usage; plaingateway always includes usage and adds cost.
provider object Host filters and order; see Provider routing.
plugins, transforms Not supported. Any value other than null returns 400.

Request headers are on Headers. Host pinning means the gateway sends a model's requests to the same first host each time, so prompt caches on that host keep working. Host pinning, usage.cost, X-PG-Host, X-PG-Cost-USD, and X-PG-Request-Id are plaingateway only.