OpenAI API Integration Guide: Chat Completions Compatibility & Key Configuration

Call our large models using OpenAI Chat Completions compatibility: API endpoints, authentication, curl and SDK examples, request/response fields, streaming, and common error codes.

1. Overview

This site provides compatibility with the OpenAI Chat Completions (/v1/chat/completions) format. For code already working with the official OpenAI SDK or OpenAI-compatible clients, simply point the request URL to our gateway's OpenAI endpoint and replace your api_key with a site-generated sk- key. All other invocation methods remain the same.

Currently available GPT-series models are listed in the Model Marketplace (e.g., gpt-5.5, gpt-5.6-sol, gpt-5.6-terra, gpt-5.6-luna, etc.). The full list and unit pricing can be queried via GET /v1/models.

2. API Endpoints

MethodPathDescription
POST/v1/chat/completionsChat completion (non-streaming / streaming), request body uses OpenAI payload
GET/v1/modelsList of models and unit prices (no authentication required)

Gateway URL: https://www.relay-api.com. For OpenAI-compatible calls, send your requests to POST https://www.relay-api.com/v1, keeping the original paths.

3. Authentication

Authorization: Bearer sk-your-api-key

Create a key starting with sk- in "User Center → API Keys". Use the same authentication header as the official OpenAI standard; the SDK will automatically add the Authorization header.

4. Quick Start

4.1 curl (Non-streaming)

curl -X POST https://www.relay-api.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-api-key" \
  -d '{
    "model": "gpt-5.5",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Introduce yourself in three sentences."}
    ],
    "temperature": 0.7,
    "max_tokens": 512
  }'

4.2 OpenAI SDK (Python)

from openai import OpenAI

client = OpenAI(
    base_url="https://www.relay-api.com/v1",
    api_key="sk-your-api-key",
)

resp = client.chat.completions.create(
    model="gpt-5.5",
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)

After setting the base_url to the OpenAI endpoint listed above and replacing the api_key, all other calls are identical to the official SDK.

5. Request Parameters

FieldTypeRequiredDescription
modelstringYesModel slug, e.g., gpt-5.5
messagesarrayYesList of messages, elements are {role, content}; role values: system / user / assistant
temperaturenumberNoSampling temperature, default 1.0
top_pnumberNoNucleus sampling, default 1.0
max_tokensintNoMaximum output tokens
streamboolNoWhether to stream the response, default false
stopstring / arrayNoStop sequences
presence_penalty / frequency_penaltynumberNoRepetition penalty, range -2 to 2

6. Response Structure

{
  "id": "chatcmpl-123456",
  "object": "chat.completion",
  "created": 1710000000,
  "model": "gpt-5.5",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "Hello! Nice to meet you."},
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 18,
    "completion_tokens": 12,
    "total_tokens": 30
  }
}
FieldDescription
idUnique ID for this completion
choices[].messageAssistant reply; content contains the text
choices[].finish_reasonStop reason: stop / length / content_filter
usage.prompt_tokensInput token count (basis for billing)
usage.completion_tokensOutput token count (basis for billing)
usage.total_tokensTotal token count

7. Streaming Output

Add "stream": true to the request body to return an SSE stream. Each data: line is a chunk:

data: {"id": "chatcmpl-123456", "object": "chat.completion.chunk", "choices": [{"index": 0, "delta": {"role": "assistant"}, "finish_reason": null}]}

data: {"id": "chatcmpl-123456", "object": "chat.completion.chunk", "choices": [{"index": 0, "delta": {"content": "Hello"}, "finish_reason": null}]}

data: {"id": "chatcmpl-123456", "object": "chat.completion.chunk", "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]}

data: [DONE]

Clients should concatenate the choices[0].delta.content of each chunk to obtain the full response. Receiving [DONE] indicates the end of the stream. When using the OpenAI SDK, setting stream=True handles these events automatically.

8. Common Error Codes

HTTP StatusMeaningSuggested Action
400Invalid request parameters (model missing, empty messages, etc.)Check request body fields
401Invalid or missing API keyVerify Authorization header and key format
403Key disabled, insufficient balance, or unauthorized model/routeTop up or check key permissions
404Path or model not foundConfirm base_url and model name
429Rate limit triggeredRetry with exponential backoff
500Internal server errorRetry later; contact support if the issue persists

Error response body format: {"code": status_code, "message": "error_description", "data": null}.

9. Compatibility Notes

  • Supports OpenAI SDK (Python / Node.js, etc.) via custom base_url configuration.
  • Supports various OpenAI-compatible clients (LobeChat, ChatBox, NextChat, One API, etc.) by configuring a custom interface address.
  • Model names must match the slug returned by GET /v1/models.

Base URL Note: This site accepts /v1beta/models/... and /v1beta/v1beta/models/... (as well as /v1/... and /v1/v1/...), so whether your client appends /v1 or /v1beta does not affect calls: setting the Base URL to the domain root or an address containing /v1beta will both work. Please query and copy the model ID from the "Model ID" section in the top-right corner of the "Tokens" page in the console.