Clients and tools

TypeScript

The official Node.js client.

@astorie/client is the official client for Node.js. It ships ESM and CommonJS builds with types included, and has no runtime dependencies.

Install

npm install @astorie/client@0.1.0-beta.1

Requires Node.js 20 or later. The package is a pre-release, so install the exact version shown.

Configure

With no options, the client reads ASTORIE_API_KEY and ASTORIE_BASE_URL from the environment.

client.ts
import { Astorie } from "@astorie/client";

const client = new Astorie({
  apiKey: process.env.ASTORIE_API_KEY,
  baseURL: "https://astorie.ai/api/gateway",
  timeoutMs: 60_000,        // per API request
  uploadTimeoutMs: 600_000, // per file upload
  maxRetries: 3,
});

Run a model

run.ts
const input = {
  prompt: "A red chair in a sunlit studio",
  aspect_ratio: "1:1",
  resolution: "1K",
  output_format: "png",
};

const { job, idempotencyKey } = await client.run("google/nano-banana-2", input, {
  maxChargeAmount: "1.000000",
});

if (job.status === "succeeded") {
  const bytes = await client.downloadAsset(job.output.assets[0]);
}

run() is submit() followed by wait(). Use them separately when you want to store the job ID before waiting, or wait somewhere else.

Methods

MethodCalls
listModels()GET /v1/models
getModel(model)GET /v1/capabilities
quote(model, input)POST /v1/quotes
getQuote(id)GET /v1/quotes/{id}
submit(model, input, options)POST /v1/jobs, returns { job, idempotencyKey, replayed }
getJob(id)GET /v1/jobs/{id}
listJobs({ limit, cursor })GET /v1/jobs
wait(id, { timeoutMs, pollIntervalMs })Polls getJob until the job is final
run(model, input, options)submit, then wait, with the same key
cancel(id)POST /v1/jobs/{id}/cancel
getBalance()GET /v1/balance
listLedger({ afterSeq, limit })GET /v1/ledger
uploadFile(data, { filename, mimeType })POST /v1/files, then the upload
createFile({ filename, mimeType, sizeBytes })POST /v1/files only. You upload the bytes.
downloadAsset(assetOrUrl)Downloads a result as a Uint8Array

submit() options are maxChargeAmount, idempotencyKey, quoteId and clientReferenceId.

Behavior worth knowing

  • Responses are returned exactly as the server sent them. Unknown fields and statuses pass through.
  • Money is always a string. Passing a number for maxChargeAmount throws a TypeError.
  • maxChargeAmount is never filled in for you.
  • A failed job is returned by wait(), not thrown.
  • wait() ignores responses older than the last one it saw.
  • If wait() times out it throws WaitTimeoutError. The job keeps running.
Warning
Use the client from server code only. It needs your API key.