Skip to main content

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.

export 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 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
}'

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​

Current Gemini availability

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
}'
Verify Responses per model

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.

Parse the actual image response

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​

ItemExpected
HTTP status200
OpenAI-compatible responsechoices[0].message.content contains text
Anthropic responseThe content array contains text
Gemini text responseText in candidates[].content.parts[].text
Responses text responseRead output_text from message content[] blocks in output[]; do not assume the first item is the answer
usageSome 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​

CheckNotes
KeyCopied in full, not expired, and the account has quota
Base URLFollow the client table; curl uses the full path
Model nameCopy from Models — case-sensitive
HeaderMust 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​