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

# Go client for the Aria Compute API

> A net/http Go 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 Go module. The API is straightforward enough that a small `net/http` client covers most needs. Drop the type below into your project.

## Client

```go aria/client.go icon=golang lines theme={null}
package aria

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"net/url"
	"os"
	"time"
)

type Client struct {
	BaseURL    string
	APIKey     string
	HTTPClient *http.Client
}

func New(apiKey string) *Client {
	return &Client{
		BaseURL:    "https://ariacompute.com/api",
		APIKey:     apiKey,
		HTTPClient: &http.Client{Timeout: 60 * time.Second},
	}
}

func (c *Client) do(method, path string, body any, out any) error {
	var buf io.Reader
	if body != nil {
		b, err := json.Marshal(body)
		if err != nil {
			return err
		}
		buf = bytes.NewReader(b)
	}
	req, err := http.NewRequest(method, c.BaseURL+path, buf)
	if err != nil {
		return err
	}
	req.Header.Set("Authorization", "Bearer "+c.APIKey)
	req.Header.Set("Accept", "application/json")
	if body != nil {
		req.Header.Set("Content-Type", "application/json")
	}
	res, err := c.HTTPClient.Do(req)
	if err != nil {
		return err
	}
	defer res.Body.Close()
	if res.StatusCode >= 400 {
		b, _ := io.ReadAll(res.Body)
		return fmt.Errorf("%d: %s", res.StatusCode, string(b))
	}
	if out != nil {
		return json.NewDecoder(res.Body).Decode(out)
	}
	return nil
}

// Wallet returns the current wallet balance.
func (c *Client) Wallet() (map[string]any, error) {
	var out map[string]any
	return out, c.do("GET", "/billing/wallet", nil, &out)
}

// DownloadModel streams a model bundle to dest.
func (c *Client) DownloadModel(slug, quant, sdk, dest string) error {
	q := url.Values{"quant": {quant}, "sdk": {sdk}}
	req, _ := http.NewRequest("GET", fmt.Sprintf("%s/models/%s/download?%s", c.BaseURL, slug, q.Encode()), nil)
	req.Header.Set("Authorization", "Bearer "+c.APIKey)
	res, err := c.HTTPClient.Do(req)
	if err != nil {
		return err
	}
	defer res.Body.Close()
	if res.StatusCode >= 400 {
		return fmt.Errorf("download failed: %d", res.StatusCode)
	}
	f, err := os.Create(dest)
	if err != nil {
		return err
	}
	defer f.Close()
	_, err = io.Copy(f, res.Body)
	return err
}
```

## Usage

```go theme={null}
client := aria.New(os.Getenv("ARIA_API_KEY"))

wallet, err := client.Wallet()
if err != nil {
	log.Fatal(err)
}
fmt.Println(wallet)

if err := client.DownloadModel("gemma-4-e2b-it", "int4", "v1.0", "./gemma-4-e2b-it_q4.zip"); err != nil {
	log.Fatal(err)
}
```

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


## Related topics

- [Aria Compute SDKs and client libraries](/sdks/overview.md)
- [Python client for the Aria Compute API](/sdks/python.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)
