OpenAI Chat API

This platform provides a chat endpoint compatible with the OpenAI Chat Completions API.

This document is intended for client-side integrators and focuses on the public request path, authentication method, request parameters, and example payloads. Field names and JSON structure are kept as close as possible to the native OpenAI Chat Completions API.

Overview:

  • Endpoint: POST /v1/chat/completions
  • Capability type: chat / text generation
  • Response modes:
    • When stream = false or omitted: standard JSON response
    • When stream = true: text/event-stream SSE response
  • Protocol style: the request body follows the native OpenAI Chat Completions structure and does not wrap content in an extra input field

Current scope:

  • Covers only POST /v1/chat/completions
  • POST /v1/responses is also supported, but is documented separately at /docs/api-reference/text/openai-response-api
  • Does not cover other OpenAI endpoints such as embeddings, images, or audio

1. API Overview

  • HTTP method: POST
  • Request path: /v1/chat/completions
  • Content-Type: application/json
  • Response type:
    • Non-streaming: application/json
    • Streaming: text/event-stream

2. Authentication and Headers

Example headers:

Authorization: Bearer YOUR_REACH_API_KEY
Content-Type: application/json

At least one of Authorization or x-api-key must be provided.

Header details:

HeaderRequiredDescription
AuthorizationNoPlatform API key in the format Bearer sk-xxxxxx
x-api-keyNoYou can also pass the platform API key directly in this header
Content-TypeYesMust be application/json

3. Request Body

The request body follows the native OpenAI Chat Completions object structure:

{
  "model": "YOUR_MODEL_ID",
  "messages": [
    {
      "role": "user",
      "content": "Please introduce yourself in one sentence."
    }
  ],
  "temperature": 0.2,
  "stream": false
}

3.1 Top-Level Parameters

FieldTypeRequiredDescription
modelstringYesModel ID
messagesarray<object>YesChat message list, at least one item
temperaturenumberNoSampling temperature
top_pnumberNoNucleus sampling parameter
nintegerNoNumber of candidate results
max_tokensintegerNoMaximum number of output tokens
max_completion_tokensintegerNoNew output token limit supported by some models
stopstring or array<string>NoStop sequences
streambooleanNoWhether to return SSE streaming output
stream_optionsobjectNoAdditional streaming configuration such as include_usage
toolsarray<object>NoTool definitions
tool_choicestring or objectNoTool calling strategy
parallel_tool_callsbooleanNoWhether parallel tool calls are allowed
response_formatobjectNoStructured output configuration
presence_penaltynumberNoPenalty for topic novelty
frequency_penaltynumberNoRepetition penalty
logit_biasobjectNoToken bias configuration
userstringNoEnd-user identifier

3.2 messages Parameter

Each message uses the following structure:

FieldTypeRequiredDescription
rolestringYesRole. Common values: system, user, assistant, tool
contentstring or array<object>YesMessage content. Can be plain text or an array of content blocks
namestringNoOptional role name
tool_call_idstringNoUsed to associate tool calls when role = tool

Text example:

{
  "role": "user",
  "content": "Write a product introduction in no more than 50 words."
}

Content block example:

{
  "role": "user",
  "content": [
    {
      "type": "text",
      "text": "Please describe this image."
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://cdn.example.com/demo.png"
      }
    }
  ]
}

4. Request Examples

4.1 Standard Non-Streaming Request

curl -X POST "https://direct.reachapi.ai/v1/chat/completions" \
  -H "Authorization: Bearer YOUR_REACH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [
      {
        "role": "user",
        "content": "Introduce ReachAPI in one sentence."
      }
    ],
    "temperature": 0.2
  }'

4.2 Streaming Request

curl -X POST "https://direct.reachapi.ai/v1/chat/completions" \
  -H "Authorization: Bearer YOUR_REACH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [
      {
        "role": "user",
        "content": "Summarize today'\''s priorities in three lines."
      }
    ],
    "stream": true,
    "stream_options": {
      "include_usage": true
    }
  }'

4.3 Request with Tool Definitions

curl -X POST "https://direct.reachapi.ai/v1/chat/completions" \
  -H "Authorization: Bearer YOUR_REACH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [
      {
        "role": "user",
        "content": "Help me check the weather in Shanghai."
      }
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Get weather information for a city",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {
                "type": "string"
              }
            },
            "required": ["city"]
          }
        }
      }
    ],
    "tool_choice": "auto"
  }'

5. Successful Response

Example non-streaming response:

{
  "id": "chatcmpl_123",
  "object": "chat.completion",
  "created": 1710000000,
  "model": "YOUR_MODEL_ID",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello, I am a model-powered assistant."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 18,
    "total_tokens": 30
  }
}

6. Streaming Response

When stream = true, the endpoint returns OpenAI-style SSE events:

data: {"id":"chatcmpl_123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl_123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"}}]}

data: [DONE]

7. Error Response

OpenAI-style error example:

{
  "error": {
    "message": "Field `messages` is required",
    "type": "invalid_request_error",
    "param": null,
    "code": "MISSING_REQUIRED_FIELD"
  }
}

Common scenarios:

  • Missing model in the request body
  • Missing messages in the request body
  • Invalid JSON payload
  • Authentication failure

8. Compatibility Notes

  • This document lists commonly used fields and example payloads. Actual field names and structures follow the OpenAI Chat Completions API.
  • This endpoint only covers the Chat Completions path and does not represent the full OpenAI API surface.
  • If you use newer or experimental official fields, validate them against the actual capabilities available on your gateway.

9. Supported Models and Reference Pricing

The following prices are summarized from the unified pricing document and apply to the GPT text models currently listed. Pricing was checked on 2026-04-17. For detailed pricing rules, refer to gpt.md.

ModelInputCached inputOutput
gpt-5.4$2.50 / 1M tokens$0.25 / 1M tokens$15.00 / 1M tokens
gpt-5.3-codex$1.75 / 1M tokens$0.175 / 1M tokens$14.00 / 1M tokens
gpt-5.2$1.75 / 1M tokens$0.175 / 1M tokens$14.00 / 1M tokens
gpt-5.1-codex$1.25 / 1M tokens$0.125 / 1M tokens$10.00 / 1M tokens
gpt-5.1$1.25 / 1M tokens$0.125 / 1M tokens$10.00 / 1M tokens
gpt-5$1.25 / 1M tokens$0.125 / 1M tokens$10.00 / 1M tokens
gpt-5.4-mini$0.75 / 1M tokens$0.075 / 1M tokens$4.50 / 1M tokens
gpt-5-mini$0.25 / 1M tokens$0.025 / 1M tokens$2.00 / 1M tokens

Notes:

  • Cached input refers to the unit price for cache-hit input tokens
  • If the model list changes over time, use the dashboard or product configuration as the source of truth for currently enabled models

10. References

On this page