Skip to content

OpenAI-Compatible Setup

树新在线 is an OpenAI-compatible AI API gateway: change the base_url in your code to this site and use an API Key issued here — the rest of your calling code stays as it is.

This site is not an official OpenAI, Anthropic or xAI service, and has no affiliation, authorization or partnership with those companies.

ItemValue
Base URLhttps://api.treenew.online/v1
EndpointPOST /v1/chat/completions
AuthAuthorization: Bearer <API Key>
API KeyCreate one on the "Tokens" page of the console
Model listhttps://treenew.online/en/models/
Pricinghttps://treenew.online/en/pricing/

Python (openai SDK)

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.treenew.online/v1",
)

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

Node.js (openai SDK)

javascript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://api.treenew.online/v1',
});

const resp = await client.chat.completions.create({
  model: 'gpt-5.6-luna',
  messages: [{ role: 'user', content: 'Hello' }],
});
console.log(resp.choices[0].message.content);

Note the field name differs: the Node SDK uses baseURL (capital URL), Python uses base_url.

curl

bash
curl https://api.treenew.online/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-luna",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Environment variables (no code changes)

Most tools and SDKs read these two variables automatically, so you may not need to touch your code at all:

bash
export OPENAI_BASE_URL="https://api.treenew.online/v1"
export OPENAI_API_KEY="YOUR_API_KEY"

Windows PowerShell:

powershell
$env:OPENAI_BASE_URL = "https://api.treenew.online/v1"
$env:OPENAI_API_KEY  = "YOUR_API_KEY"

Some older tools read OPENAI_API_BASE (the legacy variable name). If OPENAI_BASE_URL has no effect, set both.

Differences from the official API

  • Chat completions is the only inference endpoint (POST /v1/chat/completions). Endpoints such as embeddings, images, audio, assistants and batch are not available.
  • Model names follow the list at https://treenew.online/en/models/ and do not always map one-to-one to official names. There are 16 models, from Anthropic (Claude), xAI (Grok) and OpenAI.
  • Quota consumption and rate limits depend on your account group (default or vip); the groups have different billing multipliers. See https://treenew.online/en/pricing/.

Streaming

Set stream: true and the gateway returns an SSE stream. On the client side:

  • Read the response chunk by chunk; each message starts with data: followed by JSON.
  • The stream terminates with data: [DONE].
  • Handle timeouts and dropped connections with reconnection logic; exponential backoff is a reasonable default.
  • If you run your own reverse proxy in front, check its buffering settings. Nginx, for example, will hold the stream and flush it in one go unless you set proxy_buffering off;.
python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.treenew.online/v1",
)

stream = client.chat.completions.create(
    model="gpt-5.6-luna",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)

Common errors

Each error has its own troubleshooting page. Quick reference:

ErrorMost likely causeDetails
401 UnauthorizedWrong key, missing Bearer prefix, stray whitespace from copy-paste401 errors
404 model not foundName does not match this site's list, or your group lacks accessModel not found
429 Too Many RequestsThrottling or exhausted quota — the two need opposite responses429 errors
No streaming / all at once / mid-stream cutstream not set, buffering in between, wrong client parsingStreaming failures
Timeout / 502 / 504Client timeout too short, intermediary limit, slow upstreamTimeouts & 502

Checklist

  1. Is base_url exactly https://api.treenew.online/v1? (note the api. subdomain and the trailing /v1)
  2. Does the API Key come from the "Tokens" page, and does the header include the Bearer prefix?
  3. Does the model name match the list at https://treenew.online/en/models/ exactly?
  4. Does your group support that model, and have you hit its rate limit?
  5. Does the console's usage page show the quota running out?

Home · Console