OpenAI API Access Guide: Chat Completions Compatibility & Key Configuration
Access our large language models via the OpenAI Chat Completions compatible interface. Covers API endpoints, authentication, curl/SDK examples, parameters, streaming, and error codes.
I. Overview
This site provides compatibility with the OpenAI Chat Completions (/v1/chat/completions) format. For code already running with the official OpenAI SDK or OpenAI-compatible clients, simply point your request URL to our site's OpenAI gateway, replace the api_key with your sk- key from our platform, and keep all other call methods the same.
Current available GPT series models are listed in the Model Square (e.g., gpt-5.4, gpt-5.5, gpt-5.4-mini, gpt-4o, etc.). For a complete list and unit pricing, please query GET /v1/models.
II. API Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /v1/chat/completions | Chat completions (non-streaming / streaming); request body follows OpenAI payload. |
| GET | /v1/models | List of models and unit prices (no authentication required). |
Gateway URL: https://www.relay-api.com. For OpenAI-compatible calls, please send requests to POST https://www.relay-api.com/v1, keeping the original path.
III. 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 API; the SDK will automatically add the Authorization header.
IV. 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.4",
"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.4",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
After setting base_url to the OpenAI entry point above and replacing the api_key, all other invocation methods are identical to the official SDK.
V. Request Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model slug, e.g., gpt-5.4 |
| messages | array | Yes | Message list, elements are {role, content}; role values: system / user / assistant |
| temperature | number | No | Sampling temperature, default 1.0 |
| top_p | number | No | Nucleus sampling, default 1.0 |
| max_tokens | int | No | Maximum output tokens |
| stream | bool | No | Enable streaming response, default false |
| stop | string / array | No | Stop sequence |
| presence_penalty / frequency_penalty | number | No | Repetition penalty, range -2 to 2 |
VI. Response Structure
{
"id": "chatcmpl-123456",
"object": "chat.completion",
"created": 1710000000,
"model": "gpt-5.4",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Hello! Glad to meet you."},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 12,
"total_tokens": 30
}
}
| Field | Description |
|---|---|
| id | Unique ID for this completion |
| choices[].message | Assistant response; content contains the text |
| choices[].finish_reason | Termination reason: stop / length / content_filter |
| usage.prompt_tokens | Input tokens (billing basis) |
| usage.completion_tokens | Output tokens (billing basis) |
| usage.total_tokens | Total tokens used |
VII. Streaming Output
Adding "stream": true to the request body returns an SSE stream, where 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 can concatenate choices[0].delta.content from each chunk to get the full response; receiving [DONE] indicates the end of the stream. The OpenAI SDK handles these events automatically when stream=True is passed.
VIII. Common Error Codes
| HTTP Status | Meaning | Advice |
|---|---|---|
| 400 | Invalid request parameters (model missing, empty messages, etc.) | Check request body fields |
| 401 | Invalid or missing API key | Check Authorization header and key format |
| 403 | Key deactivated, insufficient balance, or unauthorized model/route | Top up or check key permissions |
| 404 | Path or model not found | Confirm base_url and model name |
| 429 | Rate limit triggered | Retry with exponential backoff |
| 500 | Internal server error | Retry later; contact support if the issue persists |
Error response bodies consistently follow the structure: {"code": status_code, "message": "error_description", "data": null}.
IX. Compatibility Notes
- Supports OpenAI SDKs (Python / Node.js, etc.) via custom
base_url. - Supports various OpenAI-compatible clients (LobeChat, ChatBox, NextChat, One API, etc.) by configuring the custom API URL.
- Model names must match the slugs returned by
GET /v1/models.
