# API overview

Source: https://tiltas.openpanel.sh/docs/api

> The base URL, Access tokens, errors, pagination and limits of the Tiltas API.

Everything the console does goes through the Tiltas API, and so does everything an AI agent does through the
[MCP server](/docs/ai). Every endpoint has its own page in this reference, with its parameters, request and response
bodies, and samples in cURL, Python, Node.js and Go.

## Base URL

```text title="Base URL" noCopy
https://tiltas.openpanel.sh/api/v1
```

Requests and responses are JSON over HTTPS. Times are RFC 3339 in UTC. Request bodies are at most 1 MiB, and a field the
endpoint does not know is refused with `bad_request`, so a typo never passes silently.

## Access tokens

An Access token lets a script or a tool use one Account's API. Owners and Admins make them in the console:

Open **Enterprise** → **Access tokens** and choose **Create an Access token**.

Name it after what will use it, such as `terraform`. Under **May**, tick **Read everything in the Account**
(the `read` scope), **Change Devices, Services and rules** (the `write` scope), or both.

Choose when it expires: after 30 days, 90 days, 1 year, or never.

Copy the token, which starts with `qlt_`. It is shown once: Tiltas keeps only a hash of it. Store it in your secrets
manager.

Send it in the `Authorization` header:

```bash
curl https://tiltas.openpanel.sh/api/v1/accounts/acc_8f2k1/devices \
  -H "Authorization: Bearer $TILTAS_TOKEN"
```

What a token may do:

- **It belongs to one Account** and works on that Account's endpoints, the ones under `/accounts/{account_id}`. Any
  other Account answers `404`. Your Account id is in the console's address: `/app/acc_…`.
- **It acts as an Admin.** It never does what only an Owner may: change the Plan, cancel it, read invoices, set up or
  remove single sign-on, or delete the Account. Roles are in [Members and roles](/docs/concepts/members-and-roles).
- **A `read` token cannot change anything.** A write with it answers `403` `access_denied`.
- **It stops working** when it expires, when it is revoked under **Access tokens**, or when the person who made it is no
  longer an Owner or Admin of the Account.
- **It cannot make other Access tokens.**

Every change made with a token is in the [audit log](/docs/people/audit-log), with the token as the actor.

## The console's session

The console signs you in with a Magic link or [single sign-on](/docs/people/sso), and keeps the session in an
HTTP-only cookie for 30 days. A few endpoints work only with that session, not with an Access token: `/me`,
`/accounts` (the list of your Accounts, and making a new one), and accepting an invite. Writes from a browser must come
from the console's own origin; other sites' requests are refused.

## Your first request

List the Devices of a Network. Set `TILTAS_TOKEN` to an Access token with the `read` scope, and replace `acc_8f2k1`
with your Account id.

```bash tab="cURL"
curl https://tiltas.openpanel.sh/api/v1/accounts/acc_8f2k1/devices \
  -H "Authorization: Bearer $TILTAS_TOKEN"
```

```python tab="Python"
import json
import os
import urllib.request

req = urllib.request.Request(
    "https://tiltas.openpanel.sh/api/v1/accounts/acc_8f2k1/devices",
    headers={"Authorization": f"Bearer {os.environ['TILTAS_TOKEN']}"},
)
with urllib.request.urlopen(req) as res:
    for device in json.load(res)["data"]:
        print(device["name"], device["address"], "online" if device["online"] else "offline")
```

```js tab="Node.js"
const res = await fetch("https://tiltas.openpanel.sh/api/v1/accounts/acc_8f2k1/devices", {
  headers: { Authorization: `Bearer ${process.env.TILTAS_TOKEN}` },
})
const body = await res.json()
if (!res.ok) throw new Error(`${res.status} ${body.code}: ${body.detail}`)
for (const device of body.data) {
  console.log(device.name, device.address, device.online ? "online" : "offline")
}
```

```go tab="Go"
package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
)

func main() {
	req, err := http.NewRequest("GET", "https://tiltas.openpanel.sh/api/v1/accounts/acc_8f2k1/devices", nil)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("TILTAS_TOKEN"))
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()
	if res.StatusCode != http.StatusOK {
		log.Fatal(res.Status)
	}
	var body struct {
		Data []struct {
			Name    string `json:"name"`
			Address string `json:"address"`
			Online  bool   `json:"online"`
		} `json:"data"`
	}
	if err := json.NewDecoder(res.Body).Decode(&body); err != nil {
		log.Fatal(err)
	}
	for _, d := range body.Data {
		state := "offline"
		if d.Online {
			state = "online"
		}
		fmt.Println(d.Name, d.Address, state)
	}
}
```

The Node.js sample is an ES module (save it as `list-devices.mjs`) and needs Node.js 18 or later. The Python sample uses
only the standard library. Every field of a Device is on [List Devices](/docs/api/devices/listDevices).

## Ids and secrets

Every object has an id with a prefix that says what it is:

| Prefix | Object |
|---|---|
| `acc_` | Account (Network) |
| `mem_` | Member |
| `inv_` | Invite |
| `dev_` | Device |
| `key_` | Join key |
| `svc_` | Service |
| `grp_` | Group |
| `rul_` | Access rule |
| `ssh_` | SSH rule |
| `tok_` | Access token |
| `dsi_` | Device sign-in |
| `evt_` | Audit event |

Secrets have prefixes too: `qlj_` for a Join key and `qlt_` for an Access token. Both are returned once, when they are
made, and stored only as a hash. These prefixes stay as they are under the Tiltas name.

## Lists and pagination

A list answers `{ "data": [ … ] }` with every item.

The audit log is the only list in pages, newest first. Ask with `?limit=` (1 to 200, 50 by default); the answer carries
`next_cursor`. Pass it as `?cursor=` to get the next page; it is `null` on the last one.

```bash
curl "https://tiltas.openpanel.sh/api/v1/accounts/acc_8f2k1/audit-events?limit=100" \
  -H "Authorization: Bearer $TILTAS_TOKEN"
```

## Errors

An error answers with an HTTP status and a body of type `application/problem+json` ([RFC 9457](https://www.rfc-editor.org/rfc/rfc9457)):

```json title="A 409 response" noCopy
{
  "type": "about:blank",
  "title": "Conflict",
  "status": 409,
  "code": "name_taken",
  "detail": "A Device or Service is already called gitea."
}
```

Program against `code`: it is stable, while `detail` is a sentence for people and may change. Some errors also name the
`field` that was wrong. Every code, with what to do about it, is in [Errors](/docs/api/errors).

An Account you are not a Member of answers `404`, never `403`, so ids cannot be probed.

## Rate limits

- **600 requests a minute per Access token**, with bursts of up to 100.
- Sign-in emails, new Accounts, Device sign-ins, sign-in codes, Join keys and invite links have their own, lower limits,
  per IP address or per person.

Over a limit, the API answers `429` with the code `rate_limited`. Wait a few seconds and try again, more slowly.

## Versioning

The version is part of the path: `/api/v1`. Changes to the API are listed in the [Changelog](/docs/changelog).

## Next

- [List Devices](/docs/api/devices/listDevices): Every Device with its address, state and connections.

- [Create a Service](/docs/api/services/createService): Give a program on a Device a name and choose who may open it.

- [Create an Access rule](/docs/api/access/createAccessRule): Say who may reach what, on which ports.

- [Use with AI](/docs/ai): The MCP server lets an AI agent do the same with an Access token.
