← back to docs

APIX

Send one prompt, get it routed across 35+ specialist models and returned as a finished result. Two calls: plan it, then run it.

Authentication

Create a key in Settings → API keys. The secret is shown once and stored only as a hash — if you lose it, create a new key. Send it as a bearer token:

Authorization: Bearer txk_live_9f3a71c2d4e8_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Keys work on /api/parse and /api/execute only. Every other endpoint requires a signed-in session, so a leaked key cannot read your account, change billing, or mint more keys.

Quickstart

Plan, then execute. The plan tells you which models will run and what it will cost before you commit to it.

const KEY = process.env.TERMINAL_X_API_KEY;
const H = { "Content-Type": "application/json", Authorization: `Bearer ${KEY}` };
const command = "Write a listing description for a 2BR in Brooklyn";

// 1. Plan — returns the tasks and a cost estimate in credits.
const plan = await fetch("https://api.terminalxapp.com/api/parse", {
  method: "POST",
  headers: H,
  body: JSON.stringify({ command }),
}).then((r) => r.json());

console.log(plan.tasks, plan.estimatedCost);

// 2. Execute — send the SAME command plus the tasks you just got back.
//    Streams Server-Sent Events until it emits "done".
const res = await fetch("https://api.terminalxapp.com/api/execute", {
  method: "POST",
  headers: H,
  body: JSON.stringify({ command, tasks: plan.tasks }),
});

for await (const chunk of res.body) {
  for (const line of new TextDecoder().decode(chunk).split("\n")) {
    if (!line.startsWith("data: ")) continue;
    const evt = JSON.parse(line.slice(6));
    if (evt.type === "task_done") console.log(evt.taskId, evt.result);
    if (evt.type === "done") console.log("credits used:", evt.creditsUsed);
  }
}

POST /api/parse

Turns a natural-language request into a task list: which model handles which piece, in what order, with a brief for each. Send { command: string }. Max 50,000 characters.

This call costs credits. Planning runs a large model, so each parse is charged to your key whether or not you go on to execute. Cache plans you reuse rather than re-parsing the same prompt.

POST /api/execute

Runs a task list and streams the results. Takes { command, tasks } — the same command you planned with, plus the array /api/parse returned. Without tasks it returns 400 missing tasks; there is no plan-and-run-in-one call.

The response is an SSE stream. Events you'll care about:

eventmeaning
task_startA specialist began. Carries taskId and model.
task_chunkStreamed output for a task.
task_doneA task finished. Carries result and credits.
task_errorA task failed. It is not billed.
doneRun complete. Carries creditsUsed and creditsRemaining.

Runs are durable. If your connection drops the run keeps going and still bills — it is not cancelled by disconnecting.

Credits and limits

A key holds credits of its own. Loading a key moves credits out of the account balance and into the key; the key then spends only what it holds, and stops when it runs dry. Nothing a key does can reach the rest of the account.

Admission happens before a run starts, so a run that begins is charged what it actually costs. A key can therefore finish slightly under zero on the run that empties it, then refuses further work — it will never overspend by multiples. Unspent credits return to the account when the key is revoked.

  • Keys expire after 90 days by default.
  • Connectors are off by default. A key cannot touch your Gmail, Stripe or GitHub unless you switch it on for that key specifically.
  • Every call is recorded — models used, credits charged, duration. Read it under the key in settings. Prompts and results are never stored in that log.
  • Revoking a key stops it on the next request.

Errors

statuserrorwhat to do
401unauthorizedKey is missing, malformed, revoked or expired.
402key_out_of_creditsAdd credits to the key in settings.
400missing tasksCall /api/parse first and pass its tasks array.
403connectors_not_allowedEnable connectors for this key, or drop those steps.
429too_many_keysYou have 20 active keys. Revoke one.

Errors on /api/execute arrive as an SSE event with type: "error" rather than an HTTP status, because the stream has usually already started.

Something missing? Email support@terminalxapp.com.