API reference

POST /v1/chat/completions

LLMs Text

POST /v1/chat/completions

OpenAI-compatible protocol with fields matching the official API. Intended for:

  • Official OpenAI SDKs (openai-python / openai npm)
  • Any OpenAI-compatible client that supports configuring base_url
  • IDE plugins such as Cursor, Cline, and Continue
  • Frameworks such as LangChain and LlamaIndex

Endpoint

POST https://relay.4aicode.com/v1/chat/completions

Request

POST /v1/chat/completions HTTP/1.1
Host: relay.4aicode.com
Authorization: Bearer sk-4ai-xxxxxxxxxxxxxxxx
content-type: application/json

{
  "model": "gpt-5.6-terra",
  "stream": true,
  "messages": [
    { "role": "system", "content": "You are helpful." },
    { "role": "user",   "content": "Write fizzbuzz in Go." }
  ]
}

Supported Models

GPT-6:

ModelBest for
gpt-6-astraNew-generation flagship; short-context input $1.50/M and output $7.50/M (15% of official price)
gpt-6.1-solGPT-6.1 flagship for complex coding and long-running tasks; $0.30/M input and $1.50/M output (15% of list price)
gpt-6-solGPT-6 flagship for complex coding and long-running tasks; $0.30/M input and $1.50/M output (15% of list price)
gpt-6-lunaLightweight GPT-6 model for fast everyday tasks; $0.015/M input and $0.075/M output (15% of list price)

GPT-5 series:

ModelBest for
gpt-5.6-solFlagship model, prioritized for complex coding and long-running tasks; supports max reasoning effort
gpt-5.6-terraBalanced tier with excellent value
gpt-5.6-lunaFast and affordable; sufficient for everyday use
gpt-5.5Previous-generation general-purpose model
gpt-5.4General-purpose use
gpt-5.4-miniFast and affordable
gpt-5.3-codexCode optimization

Google Gemini:

ModelBest for
google/gemini-3.1-pro-previewGoogle Gemini Pro preview
google/gemini-3-flash-previewGoogle Gemini Flash preview
google/gemini-2.5-flashStable Google Gemini Flash model
google/gemini-2.5-proStable Google Gemini Pro model

GPT-5.2 and earlier models have been deprecated upstream. Other models, such as gpt-4o and gpt-4, will be rejected with a 400 response whose error message includes a list of available models.

Model availability depends on upstream support and service status. If the upstream service reports that a model is unsupported, the relay returns an explicit 400 response directly.

Ignored Parameters

The following parameters are accepted but have no effect, ensuring SDK compatibility without errors:

  • logit_bias
  • user
  • functions (use the newer tools instead)

Response

Matches the official OpenAI response format:

  • choices[].message.content
  • choices[].finish_reason
  • usage (prompt_tokens / completion_tokens / total_tokens)

Streaming format:

data: {"choices":[{"delta":{"content":"Hello"}}]}
data: {"choices":[{"delta":{"content":", world"}}]}
data: [DONE]

Complete Examples

Python

from openai import OpenAI

client = OpenAI(
    base_url="https://relay.4aicode.com/v1",
    api_key="sk-4ai-xxxxxxxxxxxxxxxx",
)

resp = client.chat.completions.create(
    model="gpt-5.4",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Introduce yourself in one sentence"},
    ],
)
print(resp.choices[0].message.content)

TypeScript

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://relay.4aicode.com/v1",
  apiKey: process.env.OPENAI_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "gpt-5.4-mini",
  messages: [{ role: "user", content: "hi" }],
});
console.log(resp.choices[0].message.content);

Errors

HTTPMeaning
400Invalid field / model not in the allowlist
401Invalid token
403Team suspended
429Rate limit or quota exceeded
502Upstream OpenAI service instability
503Upstream services are temporarily unavailable; see Service Cooldowns and Retries

Differences from /v1/messages

Aspect/v1/messages/v1/chat/completions
ProtocolAnthropicOpenAI
Available modelsAll Claude modelsgpt-5* / google/gemini-*
Required fieldsmax_tokens—
Usage fieldsinput_tokens / output_tokensprompt_tokens / completion_tokens