Tutorials

Build with SmarToken from first API call to production route checks

Use these tutorials to connect a compatible SDK, compare Chinese model routes and add the operational habits needed before a real customer-facing rollout.

Beginner10 minutes

First API call

Create a key, configure the OpenAI SDK and send a non-streaming Chat Completions request.

Open tutorial
Intermediate15 minutes

Streaming chat response

Use stream: true, read server-sent events and show partial output in a chat interface or CLI.

Open tutorial
Intermediate20 minutes

Model switching workflow

Compare DeepSeek, Qwen and Kimi on the same prompt set before choosing a default route.

Open tutorial
Intermediate20 minutes

OpenRouter migration

Move China-model traffic from OpenRouter-style routing to SmarToken with a controlled evaluation run.

Open tutorial
Advanced15 minutes

Production key rotation

Separate keys by service, rotate exposed keys and keep private secrets out of browser code.

Open tutorial
Beginner12 minutes

Cost and balance review

Estimate token spend, review wallet history and decide when to use a lower-cost route.

Open tutorial

Quickstart path

The shortest reliable path to a first call

A successful first call should prove authentication, endpoint configuration, model ID and basic logging. It does not need to solve every production concern on day one.

01

Create a server-side key

Sign in, create an API key in the console and store it as SMTOKEN_API_KEY in your backend or local secret store.

02

Set the compatible base URL

Keep the OpenAI SDK, but set baseURL to the SmarToken /v1 endpoint so requests go through the gateway.

03

Choose a model for one job

Start with a task-specific route such as deepseek-chat for coding value, kimi-k2 for long context or qwen-plus for multilingual application behavior.

04

Measure before scaling

Save prompt, answer, model, latency and cost for the first test set so route changes are based on evidence.

SDK sample

OpenAI SDK shape with a SmarToken base URL

Keep secrets out of frontend code. This sample belongs in a backend route, server action, worker or CLI environment where environment variables are private.

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.SMTOKEN_API_KEY,
  baseURL: "https://thesmartoken.com/v1",
});

const response = await client.chat.completions.create({
  model: "deepseek-chat",
  messages: [{ role: "user", content: "Give me a short migration checklist." }],
});

console.log(response.choices[0]?.message?.content);

Troubleshooting

Common first-run issues

Most early issues come from key handling, balance, concurrency or model selection. Fix those before assuming the model route is unsuitable.

SymptomFirst check
401 UnauthorizedCheck the Bearer token, confirm the key was not revoked and make sure the request is sent server-side.
429 Rate limitedReduce concurrency, add exponential backoff and retry later. Include timestamp and model ID if filing a ticket.
Insufficient balanceAdd balance, shorten the prompt or choose a lower-cost model before retrying the request.
Unexpected outputCompare the same prompt across two routes and add examples, format constraints or retrieval context.

Next step after the tutorials

Once the first call works, compare models on a real workflow and estimate production cost before scaling traffic.

Get API Key