TokenLab

Core Guides

TokenLab API skill for coding agents

Give a coding agent current TokenLab models, API examples, and error-handling guidance

Let my agent set this up

Copy this task to an agent already running on your computer:

Read this guide and add the TokenLab Skill to my current agent:
https://tokenlab.sh/docs/en/integrations/coding-agent-skill
Check my installed version and active configuration first.
Preserve existing accounts, providers, permissions and other settings.
Back up local files and show proposed changes.
Have me enter any API key locally; never ask for, print or paste it in chat.
Check configuration loading first.
Explain any paid request test separately before running it.

The tokenlab-api-integration skill helps coding agents add TokenLab to an application without relying on an old model list. It covers chat, images, video, audio, translation, embeddings, rerank, music, 3D, and Worlds.

The public skill is available in tokenlab-skills.

Install

npx skills add https://github.com/hedging8563/tokenlab-skills \
  --skill tokenlab-api-integration \
  -y

Run the same command again to update an existing installation. If your coding tool does not support the installer, copy skills/tokenlab-api-integration/ from the repository into its shared skills or rules directory.

To confirm installation, ask the agent to list its available skills and look for tokenlab-api-integration.

What the skill can help with

  • Create a runnable example for a TokenLab API.
  • Read the current model list and model-specific fields.
  • Choose Chat Completions, Responses, Anthropic Messages, or Gemini format.
  • Handle model-name suggestions, rate limits, and retry timing.
  • Keep API keys out of prompts and source code.

The skill does not replace the API reference. For exact fields and response objects, use the linked TokenLab documentation.

Create an API key

Open Console → API keys, create a key, and store it in an environment variable. A TokenLab API key starts with sk-.

export TOKENLAB_API_KEY="sk-your-api-key"

Never paste a key into an agent prompt, frontend code, screenshot, or public repository. Ask the agent to read it from the environment instead.

First request

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["TOKENLAB_API_KEY"],
    base_url="https://api.tokenlab.sh/v1",
)

response = client.chat.completions.create(
    model="gpt-5.6-luna",
    messages=[{"role": "user", "content": "Hello!"}],
)

print(response.choices[0].message.content)

Install the OpenAI SDK and run the file:

pip install openai
python app.py

Ask the agent to use current model data

Model IDs, fields, and prices change. The skill can read:

# Compact API overview
curl https://api.tokenlab.sh/llms.txt

# Current models
curl "https://api.tokenlab.sh/v1/models" \
  -H "Authorization: Bearer $TOKENLAB_API_KEY"

# Models for a non-chat task
curl "https://api.tokenlab.sh/v1/models?recommended_for=image" \
  -H "Authorization: Bearer $TOKENLAB_API_KEY"

# Fields and formats for one model
curl "https://api.tokenlab.sh/v1/models/gpt-image-2" \
  -H "Authorization: Bearer $TOKENLAB_API_KEY"

recommended_for supports image, video, music, 3d, tts, stt, embedding, rerank, and translation.

Keep the API format consistent

Read tokenlab.accepted_request_formats from the selected model before generating code.

FormatEndpoint
Chat Completions/v1/chat/completions
Responses/v1/responses
Anthropic Messages/v1/messages
Gemini/v1beta/models/{model}:generateContent

A conversation or tool call should stay in one format. Model-specific fields are not automatically converted between formats.

Let errors guide safe changes

OpenAI-compatible errors may include did_you_mean, suggestions, hint, retryable, and retry_after. The agent should still use the HTTP status and error code as the primary signal.

  • A wrong model ID can be corrected with did_you_mean after user approval when changing models matters.
  • 429 can be retried after Retry-After.
  • Validation, authentication, balance, and permission errors require a change; repeating the same request will not help.
  • A create-request timeout must be checked for an existing task before the agent sends another create request.

Example requests for the agent

Use the TokenLab API skill to add image generation to this Node.js app.
Read the current model details before choosing fields.
Keep the API key in TOKENLAB_API_KEY and add one runnable test.
Use TokenLab Chat Completions in this Python service.
Keep the existing OpenAI SDK and change only the Base URL, API key source, and model.

Help

For API or account questions, use in-app Support; review the preview and submit explicitly. For a particular request, start with Requests and follow the investigation guide. Report defects in the Skill itself through GitHub Issues.

On this page