> ## 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.

# Python client for the Aria Compute API

> A tiny requests-based Python client for Aria Compute: authenticate with an API key, list models, download bundles, and query billing.

Aria Compute does not ship an official Python package. The API is small enough that a minimal `requests` wrapper covers almost every use case. Copy the class below into your project.

## Install

```bash theme={null}
pip install requests
```

## Client

```python aria_compute.py icon="python" lines theme={null}
import os
from typing import Optional
import requests

class AriaCompute:
    def __init__(self, api_key: str, base_url: str = "https://ariacompute.com/api"):
        self.base_url = base_url.rstrip("/")
        self.session = requests.Session()
        self.session.headers.update({
            "Authorization": f"Bearer {api_key}",
            "Accept": "application/json",
        })

    def _get(self, path: str, **kwargs):
        r = self.session.get(f"{self.base_url}{path}", **kwargs)
        r.raise_for_status()
        return r.json()

    def _post(self, path: str, json=None, **kwargs):
        r = self.session.post(f"{self.base_url}{path}", json=json, **kwargs)
        r.raise_for_status()
        return r.json()

    # Models
    def list_models(self):
        return self._get("/models")

    def download_model(self, slug: str, quant: str, sdk: str, dest: str):
        url = f"{self.base_url}/models/{slug}/download"
        params = {"quant": quant, "sdk": sdk}
        with self.session.get(url, params=params, stream=True, allow_redirects=True) as r:
            r.raise_for_status()
            with open(dest, "wb") as f:
                for chunk in r.iter_content(chunk_size=1 << 20):
                    f.write(chunk)

    # Billing
    def wallet(self):
        return self._get("/billing/wallet")

    def create_payment(self, provider: str, amount: float, currency: str):
        return self._post("/billing/payments", json={
            "provider": provider, "amount": amount, "currency": currency,
        })
```

## Usage

```python theme={null}
client = AriaCompute(api_key=os.environ["ARIA_API_KEY"])

for model in client.list_models()["models"]:
    print(model["slug"])

client.download_model(
    slug="gemma-4-e2b-it",
    quant="int4",
    sdk="v1.0",
    dest="./gemma-4-e2b-it_q4.zip",
)

print(client.wallet())
```

<Note>
  For the China site pass `base_url="https://ariacompute.cn/api"`. Accounts, wallets, and keys are region-scoped: a key issued on `.com` does not work on `.cn`.
</Note>

## Retries and timeouts

The backend returns standard HTTP status codes. Wrap calls in `requests.adapters.HTTPAdapter` with `urllib3.util.Retry` to retry transient `5xx` and `429` responses, and always set a `timeout`:

```python theme={null}
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

retry = Retry(total=5, backoff_factor=0.5, status_forcelist=[429, 500, 502, 503, 504])
client.session.mount("https://", HTTPAdapter(max_retries=retry))
client.session.request = lambda method, url, **kw: requests.Session.request(
    client.session, method, url, timeout=kw.pop("timeout", 30), **kw
)
```


## Related topics

- [Aria Compute SDKs and client libraries](/sdks/overview.md)
- [Go client for the Aria Compute API](/sdks/go.md)
- [Node.js client for the Aria Compute API](/sdks/nodejs.md)
- [Authenticate requests to the Aria Compute API](/authentication.md)
- [Aria Compute REST API reference](/api-reference/introduction.md)
