Torki API
Getting Started with the Torki API
Overview
The Torki API lets your own code call the four Torki models through an OpenAI-compatible interface. Every Torki account can use it: sign in to Torki Platform, add credit, create a key and send your first request.
If you already use an OpenAI SDK, you change three things: the base URL, the API key and the model name.
What you need
- A Torki account. There is nothing to request and no Torki plan to buy. Torki Platform signs you in with the account you use on torkiai.com.
- API credit. The API is prepaid. New accounts start at $0, and requests are refused with
402until you add credit.
Get started
1. Open Torki Platform
Go to platform.torkiai.com and sign in with your Torki account. From the Torki app you can also go to Settings → API and click Open Torki Platform. Your first visit creates a personal organization: the credit, the keys and the limits all belong to it.
The dashboard's Get started panel walks through the next three steps: Add credit, Create an API key and Send a ready request.
2. Add credit
Click Add credit, or open the account menu at the bottom of the sidebar and choose Settings → Billing. Add your billing details once (they are printed on your tax invoice), pick a pack under Add funds and pay. Credit appears as soon as the payment is confirmed, usually within seconds. Packs, currencies and invoices are in API Credit, Billing and Invoices.
3. Create an API key
Open API keys and click Create key. Give the key a name, click Create key, then copy it from the Save your key window. The full key is shown only once: Torki keeps only a hash of it. Keys start with tk_live_.
4. Send your first request
The base URL is https://platform.torkiai.com/v1 (https://torkiai.com/api/v1 works too). Send your key in the Authorization header:
export TORKI_API_KEY="tk_live_..."
curl https://platform.torkiai.com/v1/chat/completions \
-H "Authorization: Bearer $TORKI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "torki-pulse",
"messages": [{"role": "user", "content": "Write a haiku about the sea."}]
}'
The same request with the OpenAI Python SDK:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://platform.torkiai.com/v1",
api_key=os.environ["TORKI_API_KEY"],
)
resp = client.chat.completions.create(
model="torki-pulse",
messages=[{"role": "user", "content": "Write a haiku about the sea."}],
)
print(resp.choices[0].message.content)
The OpenAI Node.js SDK works the same way: set baseURL to the same address. A Node.js example is in the API reference.
5. Check it arrived
Open Logs in Torki Platform. Each request has a row with its status, model, tokens, latency and cost. The Save your key window also has Send a test request and View in Logs, so you can test a new key without writing any code.
Good to know
- The Playground runs the same models at the same prices, from the same credit. Use it to try prompts before you write code.
- Any OpenAI-compatible SDK works. The Torki API speaks the chat completions format; the full list of supported fields is in the API reference.
- Torki agent keys (from a published agent) are a different kind of key and don't work with the Torki API.
API credit is separate from your Torki app plan and from the app's usage credits. One can't pay for the other, and API usage never counts toward your app limits.
Keep keys secret. Never put a key in client-side code, a mobile app or a public repository: anyone who has it can spend your credit. If a key leaks, delete it on API keys and create a new one.
FAQ
Why does my first request return 402?
Your organization has no API credit yet. Add credit in Settings → Billing and send the request again.
Do I need to request access?
No. The Torki API is open to every Torki account. If Torki Platform says API access is off, access for your account was turned off; contact support@torkiai.com.
Which model should I start with?
torki-pulse is the fastest and cheapest, torki-orbit is the everyday all-rounder, and torki-stellar and torki-cosmos think before they answer. See Torki API Models and Pricing.
Do I need the API for Torki Code?
No. Torki Code in Torki AI for Mac uses your ordinary Torki account and needs no API key.