Docs / SDKs & tools

JavaScript / TypeScript SDK

@apipods/sdk is a fully typed client for Node.js 18+, Bun, Deno and edge runtimes. It has no dependencies and uses the platform fetch. Current version: 2.4.0.

Install

$ npm i @apipods/sdk
Warning: Use the SDK on the server only. Never ship an API key to a browser or mobile app; proxy calls through your backend instead.

Create a client

client.ts
import { Apipods } from "@apipods/sdk";

const apipods = new Apipods(); // reads process.env.APIPODS_API_KEY

// or configure explicitly
const custom = new Apipods({
  apiKey: process.env.APIPODS_API_KEY,
  timeoutMs: 30_000,
  maxRetries: 3,
});

Request and response types mirror the JSON exactly (camelCase), so Pod, Endpoint, Job and NetworkVolume types are exported for your own code.

Manage pods

pods.ts
const pod = await apipods.pods.create({
  name: "llama-finetune",
  gpuTypeId: "NVIDIA_H100_80GB_SXM",
  gpuCount: 1,
  regionId: "eu-nl-1",
  image: "apipods/pytorch:2.9.0-py3.12-cuda12.8.1",
  containerDiskInGb: 50,
  volumeInGb: 100,
  ports: [
    { port: 8888, protocol: "http" },
    { port: 22, protocol: "tcp" },
  ],
});
await pod.waitUntilRunning();
console.log(pod.id, pod.status, pod.costPerHr);

for await (const p of apipods.pods.list({ status: "RUNNING" })) {
  console.log(p.id, p.name);
}

await apipods.pods.stop(pod.id);
await apipods.pods.terminate(pod.id);

Call serverless endpoints

run.ts
const ep = apipods.endpoint("ep_4n8wq2zt");

const result = await ep.runSync({ input: { prompt: "a lighthouse", steps: 4 } });
console.log(result.status, result.delayTime, result.executionTime, result.output);

const job = await ep.run({ input: { prompt: "Tell me a story" }, webhook: "https://example.com/hooks/apipods" });
for await (const chunk of job.stream()) process.stdout.write(String(chunk.output));

const existing = ep.job("job_3x9wq2mt");
console.log(await existing.status());
await existing.cancel();

console.log(await ep.health());
await ep.purgeQueue();

For vLLM workers you can also use the official openai package against the OpenAI-compatible route; see Deploy vLLM.

Errors

errors.ts
import { Apipods, ApipodsError } from "@apipods/sdk";

try {
  await apipods.pods.start("pod_8f2k1x9q");
} catch (err) {
  if (err instanceof ApipodsError) {
    console.error(err.status, err.code, err.message, err.requestId);
    if (err.code === "no_capacity") {
      // retry later or recreate the pod with a network volume
    }
  } else {
    throw err;
  }
}

429, 500 and 503 responses are retried automatically (maxRetries) with the same Idempotency-Key. Codes are listed in Errors.

Verify webhooks

webhook.ts
import { verifyWebhook } from "@apipods/sdk/webhooks";

export async function POST(req: Request) {
  const payload = await req.text(); // raw body, before JSON parsing
  const event = verifyWebhook(payload, req.headers.get("Apipods-Signature"), process.env.APIPODS_WEBHOOK_SECRET!);
  if (event.type === "job.completed") {
    // event.data.object is the job
  }
  return new Response(null, { status: 204 });
}

Resource reference

ResourceJavaScriptMethodsAPI reference
Podsapipods.podslist, get, create, update, start, stop, restart, terminate, logsPods
Endpointsapipods.endpointslist, get, create, update, delete, workers, metrics, logsEndpoints
Runtimeapipods.endpoint(id)run, runSync, job, health, purgeQueueJobs
Templatesapipods.templateslist, get, create, update, deleteTemplates
Registry credentialsapipods.registryCredentialslist, create, deleteTemplates
Network volumesapipods.networkVolumeslist, get, create, update, deleteNetwork volumes
S3 keysapipods.s3Keyslist, create, deleteNetwork volumes
GPU types & poolsapipods.gpuTypes, apipods.gpuPools, apipods.regionslist, getGPU types
Secretsapipods.secretslist, get, create, update, deleteSecrets
SSH keysapipods.sshKeyslist, create, deleteSSH keys
Webhooksapipods.webhookslist, get, create, update, delete, test, deliveriesWebhooks
Billingapipods.billingbalance, usage, invoices.list, spendLimit.get, spendLimit.updateBilling
API keysapipods.apiKeyslist, create, rotate, deleteAPI keys