Quick Start
Get started with TokenSG in 5 simple steps. Send your first API request in under 5 minutes.
Step 1: Create an Account
Sign up at TokenSG Console to create your account. You'll receive free credits to get started.
Step 2: Get Your API Key
- Log in to the Dashboard
- Navigate to API Keys
- Click Create New Key
- Copy and save your key securely — it won't be shown again
Step 3: API Endpoints
TokenSG exposes two protocol-compatible endpoints under the same account, same API keys, and same billing. Pick whichever matches the SDK you're already using:
| Protocol | Base URL | Endpoints | Auth header |
|---|---|---|---|
| OpenAI-compatible | https://api.tokensg.ai/v1 (with /v1) | POST /v1/chat/completionsPOST /v1/responsesGET /v1/models | Authorization: Bearer <KEY> |
| Anthropic-compatible | https://api.tokensg.ai (without /v1) | POST /v1/messages | x-api-key: <KEY> |
Why does the /v1 differ?
This is intentional, not a typo. The OpenAI SDK appends /chat/completions itself, while the Anthropic SDK appends /v1/messages itself — so their base_url / baseURL values sit one path segment apart. Set the base URL exactly as shown above and let the SDK build the rest of the path.
(The gateway actually accepts all three auth header styles — Authorization: Bearer, x-api-key, and api-key — on either endpoint. The table above just matches each SDK's own default so you can copy-paste without extra config.)
Step 4: Send Your First Request (OpenAI-compatible)
TokenSG is fully compatible with the OpenAI API. Just change the base_url to https://api.tokensg.ai/v1.
from openai import OpenAI
client = OpenAI(
api_key="sk-your-tokensg-key",
base_url="https://api.tokensg.ai/v1",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)import OpenAI from 'openai'
const client = new OpenAI({
apiKey: 'sk-your-tokensg-key',
baseURL: 'https://api.tokensg.ai/v1',
})
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }],
})
console.log(response.choices[0].message.content)package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
body := map[string]interface{}{
"model": "gpt-4o",
"messages": []map[string]string{
{"role": "user", "content": "Hello!"},
},
}
jsonBody, _ := json.Marshal(body)
req, _ := http.NewRequest("POST",
"https://api.tokensg.ai/v1/chat/completions",
bytes.NewBuffer(jsonBody))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer sk-your-tokensg-key")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(string(data))
}curl https://api.tokensg.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-tokensg-key" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}]
}'Migrating from OpenAI?
If you're already using the OpenAI SDK, just change the base_url / baseURL to https://api.tokensg.ai/v1. No other code changes needed!
Step 5: Send Your First Request (Anthropic-compatible)
Prefer the Claude-style API? TokenSG also speaks the Anthropic Messages API natively. Point the official anthropic SDK — or plain HTTP — at https://api.tokensg.ai (no /v1) and authenticate with x-api-key.
import anthropic
client = anthropic.Anthropic(
api_key="sk-your-tokensg-key",
base_url="https://api.tokensg.ai",
)
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
print(message.content[0].text)import Anthropic from '@anthropic-ai/sdk'
const client = new Anthropic({
apiKey: 'sk-your-tokensg-key',
baseURL: 'https://api.tokensg.ai',
})
const message = await client.messages.create({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello!' }],
})
console.log(message.content[0].text)curl https://api.tokensg.ai/v1/messages \
-H "x-api-key: sk-your-tokensg-key" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello!"}]
}'See Messages API for the full field reference.
What's Next?
- Integrations — pick a CLI/SDK guide (Claude Code, OpenCode, Codex CLI, Cursor, Cline, and more)
- Chat Completions API — Full API reference with streaming support
- Messages API — Anthropic-compatible endpoint for Claude models
- Models — List of available models
- Error Codes — Error handling guide
- FAQ — Frequently asked questions