Getting started
Quickstart
Three steps from a new account to a working API call.
Create an API key
Create an account, open the console and create a key under API Keys. Keys start with sk-. Keep them on your server, never in browser code.
Store the key in an environment variable
Every example in these docs reads the key from TOKENRA_API_KEY.
# macOS / Linux
export TOKENRA_API_KEY="sk-..."
# Windows PowerShell
$env:TOKENRA_API_KEY = "sk-..."Send your first request
This calls deepseek-v4.1-flash through POST /v1/chat/completions. Any OpenAI SDK works once base_url is https://tokenra.io/v1.
curl https://tokenra.io/v1/chat/completions \
-H "Authorization: Bearer $TOKENRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash",
"messages": [
{"role": "system", "content": "You are a concise technical assistant."},
{"role": "user", "content": "Explain in two sentences what an API gateway does."}
]
}'import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["TOKENRA_API_KEY"], base_url="https://tokenra.io/v1")
resp = client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[
{"role": "system", "content": "You are a concise technical assistant."},
{"role": "user", "content": "Explain in two sentences what an API gateway does."},
],
)
print(resp.choices[0].message.content)const resp = await fetch("https://tokenra.io/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.TOKENRA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "deepseek-v4.1-flash",
messages: [
{ role: "system", content: "You are a concise technical assistant." },
{ role: "user", content: "Explain in two sentences what an API gateway does." },
],
}),
});
const data = await resp.json();
console.log(data.choices[0].message.content);import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Chat {
public static void main(String[] args) throws Exception {
String body = """
{
"model": "deepseek-v4.1-flash",
"messages": [
{"role": "user", "content": "Explain in two sentences what an API gateway does."}
]
}
""";
HttpRequest request = HttpRequest.newBuilder(URI.create("https://tokenra.io/v1/chat/completions"))
.header("Authorization", "Bearer " + System.getenv("TOKENRA_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}Set TOKENRA_API_KEY first. Python: pip install openai. JavaScript: save as .mjs and run with Node.js 18+. Java: JDK 17+, run java ClassName.java.
Next steps
- Stream long answers with
"stream": true. - Switch models by changing
model; IDs are in the model list. - Video and image models have their own endpoints, see Seedance 2.0 Pro and GPT Image 2.5 Flare.
- Claude Code and other Anthropic clients: set
ANTHROPIC_BASE_URL=https://tokenra.ioandANTHROPIC_AUTH_TOKENto your key.