> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ariacompute.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js client for the Aria Compute API

> A fetch-based Node.js client for Aria Compute: authenticate with an API key, list and download models, and query wallet and billing endpoints.

Aria Compute does not ship an official Node.js package. Use the built-in `fetch` API in Node 18+ with the tiny wrapper below.

## Client

```ts aria-compute.ts icon="node-js" lines theme={null}
import { createWriteStream } from "node:fs";
import { Readable } from "node:stream";
import { pipeline } from "node:stream/promises";

export interface AriaComputeOptions {
  apiKey: string;
  baseUrl?: string;
}

export class AriaCompute {
  private baseUrl: string;
  private headers: Record<string, string>;

  constructor(opts: AriaComputeOptions) {
    this.baseUrl = (opts.baseUrl ?? "https://ariacompute.com/api").replace(/\/$/, "");
    this.headers = {
      Authorization: `Bearer ${opts.apiKey}`,
      Accept: "application/json",
    };
  }

  private async request<T>(path: string, init: RequestInit = {}): Promise<T> {
    const res = await fetch(`${this.baseUrl}${path}`, {
      ...init,
      headers: { ...this.headers, ...(init.headers ?? {}) },
    });
    if (!res.ok) throw new Error(`${res.status} ${res.statusText}: ${await res.text()}`);
    return res.json() as Promise<T>;
  }

  listModels() {
    return this.request<{ models: unknown[] }>("/models");
  }

  wallet() {
    return this.request<{ balance: number; currency: string }>("/billing/wallet");
  }

  createPayment(provider: "stripe" | "wechat" | "alipay", amount: number, currency: string) {
    return this.request("/billing/payments", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ provider, amount, currency }),
    });
  }

  async downloadModel(slug: string, quant: string, sdk: string, dest: string) {
    const url = `${this.baseUrl}/models/${slug}/download?quant=${quant}&sdk=${sdk}`;
    const res = await fetch(url, { headers: this.headers, redirect: "follow" });
    if (!res.ok || !res.body) throw new Error(`Download failed: ${res.status}`);
    await pipeline(Readable.fromWeb(res.body as any), createWriteStream(dest));
  }
}
```

## Usage

```ts theme={null}
import { AriaCompute } from "./aria-compute";

const client = new AriaCompute({ apiKey: process.env.ARIA_API_KEY! });

const { models } = await client.listModels();
console.log(models);

await client.downloadModel("gemma-4-e2b-it", "int4", "v1.0", "./gemma-4-e2b-it_q4.zip");

console.log(await client.wallet());
```

<Note>
  For the China site pass `baseUrl: "https://ariacompute.cn/api"`. Accounts, wallets, and API keys are region-scoped.
</Note>

## Handling redirects

`GET /api/models/{slug}/download` responds with either a `302` to a short-lived S3 presigned URL or a streamed zip. `fetch` with `redirect: "follow"` handles both. Set `Accept: application/json` on the request if you want the JSON envelope (`{ mode, url, filename }`) instead.


## Related topics

- [Python client for the Aria Compute API](/sdks/python.md)
- [Go client for the Aria Compute API](/sdks/go.md)
- [Aria Compute SDKs and client libraries](/sdks/overview.md)
- [Authenticate requests to the Aria Compute API](/authentication.md)
- [aria-router runtime and FFI](/sdks/router-runtime.md)
