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.
| Item | Value |
|---|---|
| Base URL | https://api.treenew.online/v1 |
| Endpoint | POST /v1/chat/completions |
| Auth | Authorization: Bearer <API Key> |
| API Key | Create one on the "Tokens" page of the console |
| Model list | https://treenew.online/en/models/ |
| Pricing | https://treenew.online/en/pricing/ |
Python (openai SDK)
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)
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
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:
export OPENAI_BASE_URL="https://api.treenew.online/v1"
export OPENAI_API_KEY="YOUR_API_KEY"Windows 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 (
defaultorvip); 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;.
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:
| Error | Most likely cause | Details |
|---|---|---|
| 401 Unauthorized | Wrong key, missing Bearer prefix, stray whitespace from copy-paste | 401 errors |
| 404 model not found | Name does not match this site's list, or your group lacks access | Model not found |
| 429 Too Many Requests | Throttling or exhausted quota — the two need opposite responses | 429 errors |
| No streaming / all at once / mid-stream cut | stream not set, buffering in between, wrong client parsing | Streaming failures |
| Timeout / 502 / 504 | Client timeout too short, intermediary limit, slow upstream | Timeouts & 502 |
Checklist
- Is
base_urlexactlyhttps://api.treenew.online/v1? (note theapi.subdomain and the trailing/v1) - Does the API Key come from the "Tokens" page, and does the header include the
Bearerprefix? - Does the model name match the list at https://treenew.online/en/models/ exactly?
- Does your group support that model, and have you hit its rate limit?
- Does the console's usage page show the quota running out?