First call
Copy-paste examples. Get the minimal request working first, then add advanced parameters.
Prepare your key
Set the environment variable in the same terminal used to run the examples. It applies to that terminal and programs launched from it. Do not commit a real key to your repository.
- macOS / Linux / Git Bash
- Windows PowerShell
export TOKENROUTE_API_KEY="sk-your-token"
$env:TOKENROUTE_API_KEY = "sk-your-token"
The curl examples use Bash quoting and line continuation. Windows PowerShell users can use the PowerShell example under Chat Completions; Python SDK examples also cover the other protocols below.
OpenAI-compatible endpoint
A common text interface. All 36 catalog text models completed minimal calls in this run; see Vendor differences for scope.
- curl
- Python
- Node.js
- PowerShell
curl https://api.smartwan.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TOKENROUTE_API_KEY}" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{"role": "user", "content": "Hello, confirm in one sentence that you are connected."}
],
"max_tokens": 100
}'
pip install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKENROUTE_API_KEY"],
base_url="https://api.smartwan.com/v1",
)
response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "Hello, please reply: call successful"}],
max_tokens=100,
)
print(response.choices[0].message.content)
npm install openai
Save the Node.js example as example.mjs and run node example.mjs in the terminal where the key is set.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.TOKENROUTE_API_KEY,
baseURL: "https://api.smartwan.com/v1",
});
const response = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [{ role: "user", content: "Hello, please reply: call successful" }],
max_tokens: 100,
});
console.log(response.choices[0].message.content);
if (-not $env:TOKENROUTE_API_KEY) { throw "Set TOKENROUTE_API_KEY first" }
$requestHeaders = @{
Authorization = "Bearer $env:TOKENROUTE_API_KEY"
}
$requestBody = @{
model = "deepseek-v4-flash"
messages = @(@{ role = "user"; content = "Reply with OK" })
max_tokens = 1024
} | ConvertTo-Json -Depth 6
$response = Invoke-RestMethod -Method Post `
-Uri "https://api.smartwan.com/v1/chat/completions" `
-Headers $requestHeaders `
-ContentType "application/json; charset=utf-8" `
-Body ([System.Text.Encoding]::UTF8.GetBytes($requestBody))
$response.choices[0].message.content
On success, the model's reply is in choices[0].message.content.
Anthropic Messages endpoint
Use this for Claude models, or whenever you need the Anthropic format. The example uses x-api-key; Bearer is also accepted. See Authentication.
curl https://api.smartwan.com/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: ${TOKENROUTE_API_KEY}" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-haiku-4-5",
"max_tokens": 100,
"messages": [
{"role": "user", "content": "Hello, please reply: call successful"}
]
}'
The reply is in the text field of the content array.
Python (configuration verified with Anthropic SDK 1.7.0):
pip install anthropic
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["TOKENROUTE_API_KEY"],
base_url="https://api.smartwan.com",
)
response = client.messages.create(
model="claude-haiku-4-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Reply with OK"}],
)
print("".join(block.text for block in response.content if block.type == "text"))
Native Gemini endpoint
Gemini appears in the catalog. Native text calls passed on 2026-09-22 for gemini-3.6-flash, gemini-3.7-flash and gemini-3.8-flash; image generation passed for gemini-3.1-flash-image. Availability still depends on account permissions and route status.
The model name goes in the URL path, and the header is x-goog-api-key.
curl https://api.smartwan.com/v1beta/models/gemini-3.8-flash:generateContent \
-H "Content-Type: application/json" \
-H "x-goog-api-key: ${TOKENROUTE_API_KEY}" \
-d '{
"contents": [{"parts": [{"text": "Hello, please reply: call successful"}]}],
"generationConfig": {"maxOutputTokens": 100, "temperature": 0.7}
}'
The example uses the verified gemini-3.8-flash; you can choose another Gemini model that your key can access from the model list.
Python (configuration verified with Google GenAI SDK 2.24.0). Use the root Base URL and specify the version with api_version:
pip install google-genai
import os
from google import genai
from google.genai import types
client = genai.Client(
api_key=os.environ["TOKENROUTE_API_KEY"],
http_options=types.HttpOptions(
base_url="https://api.smartwan.com",
api_version="v1beta",
),
)
response = client.models.generate_content(
model="gemini-3.8-flash",
contents="Reply with OK",
)
print(response.text)
Responses API
curl https://api.smartwan.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TOKENROUTE_API_KEY}" \
-d '{
"model": "gpt-5.5",
"input": "Introduce yourself in one sentence",
"max_output_tokens": 100
}'
Representative GPT models passed this test. Chat Completions success does not establish Responses support; other models may fail because of conversion or parameter incompatibility, with errors other than not implemented. See Vendor differences.
Image generation
curl https://api.smartwan.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TOKENROUTE_API_KEY}" \
-d '{
"model": "gpt-image-2",
"prompt": "An orange cat sitting at a desk reading documentation, clean illustration style",
"n": 1,
"size": "1024x1024"
}'
Image editing uses /v1/images/edits and requires uploading a valid image file.
Common parameters
Start with the example's model, prompt, n: 1 and size: "1024x1024". The requested size does not replace checking the returned image.
Verify advanced parameters such as quality, background, output_format and output_compression for each model, endpoint and route. Do not apply one model's parameter table to every image model; these combinations are not all verified by this page.
In this test, gpt-image-2 and grok-imagine-image-quality returned data[].b64_json; Gemini returned candidates[].content.parts[].inlineData. All passed image decoding checks. Parse the actual fields and MIME type; handle data URLs and external URLs separately when present, rather than assuming an external link.
Check the actual pixel dimensions when they matter. One GPT sample requested with size: "1024x1024" decoded to 1254×1254. The requested size is not a substitute for checking the result. Image editing, masks and streaming edits were not covered in this run.
What success looks like
| Item | Expected |
|---|---|
| HTTP status | 200 |
| OpenAI-compatible response | choices[0].message.content contains text |
| Anthropic response | The content array contains text |
| Gemini text response | Text in candidates[].content.parts[].text |
| Responses text response | Read output_text from message content[] blocks in output[]; do not assume the first item is the answer |
usage | Some endpoints return token usage, useful for reconciling spend |
If HTTP 200 contains no final text, check finish_reason and the output budget: reasoning may consume output tokens first. In this test, raising glm-5-turbo from 128 to 1024 tokens produced final text; other tasks need their own budget.
Four things to check when it fails
| Check | Notes |
|---|---|
| Key | Copied in full, not expired, and the account has quota |
| Base URL | Follow the client table; curl uses the full path |
| Model name | Copy from Models — case-sensitive |
| Header | Must match the protocol — Authorization for OpenAI, x-api-key or Bearer for Anthropic, x-goog-api-key for Gemini |
Get a minimal request working first, then add temperature, tools and the rest. Still failing? See the FAQ.
Next steps
- Vendor differences — per-vendor parameter limits
- Authentication & Base URL — the full reference for URLs and auth