Examples
Node.js example
Call TokenAir from Node.js with the official OpenAI SDK.
Install
npm install openaiSet environment variables
export TOKENAIR_BASE_URL="https://api.tokenair.ai/v1"
export TOKENAIR_API_KEY="your_tokenair_api_key"Run a request
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.TOKENAIR_API_KEY,
baseURL: process.env.TOKENAIR_BASE_URL,
});
async function main() {
const completion = await client.chat.completions.create({
model: "gpt-5-mini",
messages: [
{ role: "system", content: "You write concise implementation notes." },
{ role: "user", content: "Give me a three-step API migration checklist." },
],
});
console.log(completion.choices[0].message.content);
}
main().catch((error) => {
console.error(error);
process.exit(1);
});Verify output
Run the file from a server-side Node.js environment. A successful response prints the assistant message. A 401 means the API key is missing or invalid; a model error usually means the model ID is not enabled for the account.