Skip to content

NiceAI API Quick Start ​

NiceAI is an AI model API relay. One API key lets you call Claude, GPT and Gemini models through APIs that follow the official OpenAI, Anthropic and Gemini formats. Change the base URL and API key in your tool or SDK, and your existing code keeps working.

The full documentation is in Chinese: 快速开始. This page summarises what you need to get started.

Base URLs ​

ProtocolBase URLAuth header
OpenAI compatible (Chat Completions / Responses)https://api.niceai.dev/v1Authorization: Bearer <key>
Anthropic Messages (Claude Code, Anthropic SDK)https://api.niceai.dev (no /v1)x-api-key: <key>
Geminihttps://api.niceai.dev/v1betax-goog-api-key: <key>

Create an API key at niceai.dev/keys and pick the group that matches your tool: Claude for Claude Code and the Anthropic SDK, OpenAI for Codex and the OpenAI SDK, Gemini for Gemini CLI. Available models are listed in the model plaza.

First request ​

bash
curl https://api.niceai.dev/v1/chat/completions \
  -H "Authorization: Bearer $NICEAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "<model name>", "messages": [{"role": "user", "content": "Hello"}]}'
python
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.niceai.dev/v1", api_key=os.environ["NICEAI_API_KEY"])
resp = client.chat.completions.create(model="<model name>", messages=[{"role": "user", "content": "Hello"}])
print(resp.choices[0].message.content)
js
import OpenAI from 'openai'

const client = new OpenAI({ baseURL: 'https://api.niceai.dev/v1', apiKey: process.env.NICEAI_API_KEY })
const resp = await client.chat.completions.create({ model: '<model name>', messages: [{ role: 'user', content: 'Hello' }] })
console.log(resp.choices[0].message.content)

Claude Code ​

Add this to ~/.claude/settings.json (Windows: %USERPROFILE%\.claude\settings.json):

json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.niceai.dev",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-key"
  }
}

Do not add /v1: Claude Code appends /v1/messages itself. Details (in Chinese): Claude Code 接入.

Codex CLI ​

Add a custom provider to ~/.codex/config.toml and set NICEAI_API_KEY in your environment:

toml
model = "<model name>"
model_provider = "niceai"

[model_providers.niceai]
name = "NiceAI"
base_url = "https://api.niceai.dev/v1"
wire_api = "responses"
env_key = "NICEAI_API_KEY"

Details (in Chinese): Codex CLI 接入.

Common errors ​

StatusUsual cause
404/v1 missing or duplicated in the base URL, or a wrong model name
401Invalid, incomplete or disabled API key
403Insufficient balance, or the key's group cannot use this model
429Too many requests: lower concurrency and retry with backoff

More: error codes (Chinese) · client list (Chinese) · llms.txt

NiceAI · 稳定的 AI 大模型 API 中转站