Connect to a free Chat Completions API.

Use the same free API in apps, small tools and scripts that support a custom OpenAI-compatible Chat Completions endpoint. The service chooses the upstream model, from any supported provider.

BEFORE YOU CONNECT

Does this route fit your task?

Start with a short request.

The site route can fit small text tasks. Use free as the model label and check availability. Output is capped at 256 tokens; keep the full request within six messages and 6,000 normalized JSON characters.

Copy connection settings →
Checking site API configuration… Service status · Compare separate API routes

Copy the settings into your app

API base URL
https://chinagenai.com/v1
Complete chat URL
https://chinagenai.com/v1/chat/completions
Model label
free
API key
Your ChinaGenAI site key · check key access

Use the base URL in an SDK. Use the complete chat URL only in clients that ask for a full endpoint.

  1. In your app, choose a custom OpenAI-compatible provider or endpoint.
  2. Enter the base URL, your site key and free. If the app asks for the complete Chat Completions URL, use https://chinagenai.com/v1/chat/completions.
  3. Send one short test. Confirm it succeeds before connecting a larger workflow.

The model field is a client label, not a promise of a particular model. A prefilled model name is also routed through the same free service. Brand names in our guides help people find information; they do not lock this API to Qwen, a Chinese provider or an overseas provider.

Try a standard request

The cURL example below uses Bash or zsh. For PowerShell, choose PowerShell in the request builder.

cURL request
curl 'https://chinagenai.com/v1/chat/completions' \
  -H 'Authorization: Bearer YOUR_SITE_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "free",
  "messages": [
    {
      "role": "user",
      "content": "Reply with one short sentence."
    }
  ],
  "max_tokens": 256,
  "stream": false
}'

Replace YOUR_SITE_KEY locally with your site key. The request builder can prepare the command without sending it. Check key availability before sending a request.

Use an OpenAI SDK

Install openai for Python or Node.js, or github.com/openai/openai-go/v3 in an existing Go module. Set the key in your shell, then run one example. The examples do not run a request from this page.

Choose the command for the shell you use.

Save the Node.js example as an .mjs file, or run it in a project configured for ES modules.

macOS or Linux

Bash or zsh environment variable
export CHINAGENAI_API_KEY="YOUR_SITE_KEY"

PowerShell

PowerShell environment variable
$env:CHINAGENAI_API_KEY="YOUR_SITE_KEY"

Python

Python SDK example
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://chinagenai.com/v1",
    api_key=os.environ["CHINAGENAI_API_KEY"],
    max_retries=0,
)

reply = client.chat.completions.create(
    model="free",
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(reply.choices[0].message.content)

Node.js

Node.js SDK example
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://chinagenai.com/v1",
  apiKey: process.env.CHINAGENAI_API_KEY,
  maxRetries: 0,
});

const reply = await client.chat.completions.create({
  model: "free",
  messages: [{ role: "user", content: "Say hello in one sentence." }],
});
console.log(reply.choices[0]?.message.content);

Go

In an existing Go module, run go get github.com/openai/openai-go/v3. The current Go SDK reference requires Go 1.26 or later; check its version-support notes for older toolchains.

Go SDK example
package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/option"
)

func main() {
    apiKey := os.Getenv("CHINAGENAI_API_KEY")
    if apiKey == "" {
        log.Fatal("Set CHINAGENAI_API_KEY in your shell first")
    }

    client := openai.NewClient(
        option.WithAPIKey(apiKey),
        option.WithBaseURL("https://chinagenai.com/v1"),
        option.WithMaxRetries(0),
    )
    reply, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
        Model: "free",
        Messages: []openai.ChatCompletionMessageParamUnion{
            openai.UserMessage("Say hello in one sentence."),
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if len(reply.Choices) == 0 {
        log.Fatal("No completion choice returned")
    }
    fmt.Println(reply.Choices[0].Message.Content)
}

Official Go SDK reference ↗

These examples disable SDK retries so one call does not automatically repeat after an error. An upstream attempt that fails can still count toward the daily allowance; inspect the error and availability before trying again.

Waiting longer than your Python SDK timeout? See how retries affect the total wait.

Protect your key. Set CHINAGENAI_API_KEY in the server or local shell environment. Never paste it into frontend JavaScript, a public repository or a shared code sample.

USE WHAT YOU ALREADY HAVE

Find your software.

Configuration guides explain the connection and its limits. A compatible URL does not guarantee every app feature.

18 setup routes. Long agent loops can exceed the site's 6-message and 256-token limits.

Connecting a provider directly? Compare free allowances, trials and paid APIs. Gemini and Doubao through Volcengine Ark use their own endpoints and keys.

Compatibility and current limits

Download the OpenAPI starter reference for the short-text request subset, or open the documentation index for agents. These documents describe the route; they do not make a model call.

Client featureCurrent gateway behavior
Model discoveryGET /v1/models; the free route appears when the pool is available.
Text chatPOST /v1/chat/completions; system, developer, user, assistant and tool messages.
Streaming clientsstream: true returns SSE-compatible chunks after the upstream response completes. It does not provide immediate token-by-token delivery.
Function tools and JSON modeForwarded in the standard chat format; actual model support must pass the upstream activation checks. The gateway does not execute your tools.
Browser toolsBearer-key requests and CORS preflight are supported on /v1/. Account and key-management endpoints remain separate.
Other OpenAI productsResponses API, embeddings, images, audio, files and fine-tuning are not exposed by this chat endpoint. Apps that require those APIs need their own supported connection.

The request fields user, store and metadata are accepted but not forwarded to the upstream model. Check a request body.

When enabled: 20 attempts per network or verified account per UTC day, 1 active request per key, 2 across the site, 48-hour keys, up to 6 messages and 6,000 combined input characters including tool schemas. Requested output is capped at 256 tokens. Long requests may truncate; check finish_reason. Requests accepted for processing count even if the upstream call fails. A separate site-wide daily request cap applies. No ad click or referral is required.

If your app cannot connect

  • 401: replace an expired or revoked site key. A provider’s key cannot be used as a site key.
  • 400: check the request format, input size and supported endpoint. Preflight a JSON body locally before sending it. Some apps append /v1 automatically; avoid a duplicated path.
  • 429: wait for an active slot or the next UTC day. Replacing a key does not reset allowance.
  • 503: check service availability; paused issuance is not a software configuration error.
  • 502: the upstream failed or timed out. There is no automatic paid fallback.