Skip to content
RunAPI Developer Docs
API Reference
API Reference

OpenAI Chat Completions

Send a request through RunAPI's OpenAI-compatible Chat Completions operation.

01

Overview

Use RunAPI's OpenAI-compatible Chat Completions operation with a compatible model and the protocol's request and response shapes.

Quick start

  1. Create an API key and set it as RUNAPI_API_KEY.
  2. Choose a compatible model, then send the documented path parameters and JSON body.
  3. Read the JSON response or server-sent events shown for this operation, and handle protocol errors.

Endpoint

POST /v1/chat/completions
Base URL
https://runapi.ai
Contract version
v1
Preferred authentication
Authorization: Bearer YOUR_API_TOKEN
02

Authentication carriers

RunAPI accepts each carrier listed below. Generated samples use the protocol's preferred header.

header - Preferred
Authorization: Bearer YOUR_API_TOKEN
header
x-api-key: YOUR_API_TOKEN
header
x-goog-api-key: YOUR_API_TOKEN
query
?key=YOUR_API_TOKEN
03

Compatible models

Open a model page for current pricing, rate limits, and commercial-usage details.

Show 53 compatible models
04

Request contract

JSON body

Only fields with both public protocol and RunAPI support evidence are listed. Additional JSON body fields are passed through.

JSON body9 fields
max_tokens["integer", "null"]
Optional

Compatibility generation token limit retained for supported models; model support can vary.

messagesarray
Required

Conversation messages in OpenAI Chat Completions format.

messages[].content["string", "array"]
Optional
messages[].rolestring
Required
modelstring
Required

RunAPI model identifier returned by the compatible model catalog.

stream["boolean", "null"]
Optional

Return Chat Completions chunks as server-sent events.

Default: false
temperature["number", "null"]
Optional

Sampling temperature; model support can vary.

toolsarray
Optional

Tools the model may call.

top_p["number", "null"]
Optional

Nucleus sampling probability; model support can vary.

Request example

JSON
{
  "messages": [
    {
      "content": "Say hello in one sentence.",
      "role": "user"
    }
  ],
  "model": "gpt-5.4",
  "stream": false
}
05

Synchronous response

HTTP 200

Schema

JSON
{
  "additionalProperties": true,
  "properties": {
    "choices": {
      "type": "array"
    },
    "created": {
      "type": "integer"
    },
    "id": {
      "type": "string"
    },
    "model": {
      "type": "string"
    },
    "object": {
      "const": "chat.completion",
      "type": "string"
    },
    "usage": {
      "additionalProperties": true,
      "properties": {
        "completion_tokens": {
          "type": "integer"
        },
        "prompt_tokens": {
          "type": "integer"
        },
        "total_tokens": {
          "type": "integer"
        }
      },
      "required": [
        "prompt_tokens",
        "completion_tokens",
        "total_tokens"
      ],
      "type": "object"
    }
  },
  "required": [
    "id",
    "object",
    "created",
    "model",
    "choices"
  ],
  "type": "object"
}

Example

JSON
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "Hello! How can I help today?",
        "role": "assistant"
      }
    }
  ],
  "created": 1785196800,
  "id": "chatcmpl_example",
  "model": "gpt-5.4",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 8,
    "prompt_tokens": 12,
    "total_tokens": 20
  }
}
06

SSE event: chunk

text/event-stream

Schema

JSON
{
  "additionalProperties": true,
  "properties": {
    "choices": {
      "type": "array"
    },
    "created": {
      "type": "integer"
    },
    "id": {
      "type": "string"
    },
    "model": {
      "type": "string"
    },
    "object": {
      "const": "chat.completion.chunk",
      "type": "string"
    },
    "usage": {
      "oneOf": [
        {
          "additionalProperties": true,
          "properties": {
            "completion_tokens": {
              "type": "integer"
            },
            "prompt_tokens": {
              "type": "integer"
            },
            "total_tokens": {
              "type": "integer"
            }
          },
          "required": [
            "prompt_tokens",
            "completion_tokens",
            "total_tokens"
          ],
          "type": "object"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "object",
    "choices"
  ],
  "type": "object"
}

Example

JSON
{
  "choices": [
    {
      "delta": {
        "content": "Hello"
      },
      "finish_reason": null,
      "index": 0
    }
  ],
  "id": "chatcmpl_example",
  "object": "chat.completion.chunk",
  "usage": null
}
07

Protocol error: invalid_request

HTTP 400

Schema

JSON
{
  "additionalProperties": true,
  "properties": {
    "error": {
      "additionalProperties": true,
      "properties": {
        "code": {
          "type": [
            "string",
            "null"
          ]
        },
        "message": {
          "type": "string"
        },
        "param": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": "string"
        }
      },
      "required": [
        "message",
        "type"
      ],
      "type": "object"
    }
  },
  "required": [
    "error"
  ],
  "type": "object"
}

Example

JSON
{
  "error": {
    "code": null,
    "message": "messages is required",
    "param": "messages",
    "type": "invalid_request_error"
  }
}
08

Usage

Schema

JSON
{
  "additionalProperties": true,
  "properties": {
    "completion_tokens": {
      "type": "integer"
    },
    "prompt_tokens": {
      "type": "integer"
    },
    "total_tokens": {
      "type": "integer"
    }
  },
  "required": [
    "prompt_tokens",
    "completion_tokens",
    "total_tokens"
  ],
  "type": "object"
}

Example

JSON
{
  "completion_tokens": 8,
  "prompt_tokens": 12,
  "total_tokens": 20
}
09

Generated Code Samples

Each cURL, JavaScript, and Python sample sends the validated request from this contract without requiring a protocol-specific SDK.

CURL
curl -X POST https://runapi.ai/v1/chat/completions \
  -H Authorization:\ Bearer\ YOUR_API_TOKEN \
  -H Content-Type:\ application/json \
  -d \{\"model\":\"gpt-5.4\",\"messages\":\[\{\"role\":\"user\",\"content\":\"Say\ hello\ in\ one\ sentence.\"\}\],\"stream\":false\}
JAVASCRIPT
const response = await fetch("https://runapi.ai/v1/chat/completions", {
  method: "POST",
  headers: {
  "Authorization": "Bearer YOUR_API_TOKEN",
  "Content-Type": "application/json"
},
  body: JSON.stringify({
  "model": "gpt-5.4",
  "messages": [
    {
      "role": "user",
      "content": "Say hello in one sentence."
    }
  ],
  "stream": false
})
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
console.log(data);

Install

BASH
pip install requests
PYTHON
import requests

response = requests.post(
    "https://runapi.ai/v1/chat/completions",
    headers={"Authorization": "Bearer YOUR_API_TOKEN", "Content-Type": "application/json"},
    json={"model": "gpt-5.4", "messages": [{"role": "user", "content": "Say hello in one sentence."}], "stream": False}
)
response.raise_for_status()
print(response.json())