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/sdkWarning: 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
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
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
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
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
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
| Resource | JavaScript | Methods | API reference |
|---|---|---|---|
| Pods | apipods.pods | list, get, create, update, start, stop, restart, terminate, logs | Pods |
| Endpoints | apipods.endpoints | list, get, create, update, delete, workers, metrics, logs | Endpoints |
| Runtime | apipods.endpoint(id) | run, runSync, job, health, purgeQueue | Jobs |
| Templates | apipods.templates | list, get, create, update, delete | Templates |
| Registry credentials | apipods.registryCredentials | list, create, delete | Templates |
| Network volumes | apipods.networkVolumes | list, get, create, update, delete | Network volumes |
| S3 keys | apipods.s3Keys | list, create, delete | Network volumes |
| GPU types & pools | apipods.gpuTypes, apipods.gpuPools, apipods.regions | list, get | GPU types |
| Secrets | apipods.secrets | list, get, create, update, delete | Secrets |
| SSH keys | apipods.sshKeys | list, create, delete | SSH keys |
| Webhooks | apipods.webhooks | list, get, create, update, delete, test, deliveries | Webhooks |
| Billing | apipods.billing | balance, usage, invoices.list, spendLimit.get, spendLimit.update | Billing |
| API keys | apipods.apiKeys | list, create, rotate, delete | API keys |