OpenAI API Relay Setup Guide
Step-by-step guide to configuring OpenAI API relays — environment variables, ChatBox/NextChat integration, Python SDK setup, and Codex CLI configuration.
// Recommended
Recommended Platforms
These platforms have strong OpenAI API (GPT series) support
QCode — 1:1 Official Pricing
1:1 multiplier equals official pricing, but with CNY payment and Alipay support — no credit card needed.
Weelinking — 200+ Model Aggregation
Full OpenAI model coverage plus Claude, Gemini, and more — unified management across all models.
Right Codes — Start from ¥1
¥1 top-up gives ¥5 credit, GPT 5.4 at ¥1.25/7.5 per million tokens — ultra low barrier.
// Env Setup
Environment Setup
Core: Set OPENAI_BASE_URL
Register and Get API Key
Sign up on your chosen relay platform and get your API key (usually in format sk-xxxx).
Set Environment Variables
Set the following environment variables in your terminal or config file:
Verify Connection
Run a test command to verify your configuration works.
// Code Examples
Code Examples
SDK integration for various languages
Python (OpenAI SDK)
Use the openai Python package, specify base_url to point to your relay.
from openai import OpenAI
client = OpenAI(
api_key="your-relay-api-key",
base_url="https://your-relay.com/v1"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)Node.js (OpenAI SDK)
Use the openai npm package, configure baseURL.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "your-relay-api-key",
baseURL: "https://your-relay.com/v1"
});
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }]
});cURL
Use curl directly to test API connectivity.
curl https://your-relay.com/v1/chat/completions \
-H "Authorization: Bearer your-relay-api-key" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello!"}]}'// App Integration
App Integration
Configure popular tools to use your relay
ChatBox
A cross-platform AI chat client with simple, intuitive configuration.
NextChat (ChatGPT Next Web)
An open-source ChatGPT web client with custom API endpoint support.
OpenWebUI
A powerful open-source Web UI supporting OpenAI and OAI-compatible relays.
// FAQ