# AI Governance API

> Every endpoint AI Governance serves on your realm's host, by area, with the page that explains each.

Every call here is made on your realm's own host with your session, sent as the `x-cvyuh-token` cookie;
[Call the API](../../develop/api/) shows how to get one. You need a privilege that reads the realm's configuration,
such as `RealmViewer` or `RealmOwner`, held in the realm or in a realm above it; today the same privilege can also drop
a device. Each call sees only that realm's fleet. Unlike the rest of the realm's API, the fleet spells its fields in
snake_case, and its times are seconds since the Unix epoch; a skill's `frontMatter` and the usage report are spelled in
camelCase.

```sh
curl https://foobar.cvyuh.com/api/v0/endpoint/aig/v1/api/v1/overview \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

## Discovery

What each device's tools are is part of its fleet record: `discoveries` (each tool's `kind`, `version`, `path`,
`mcp_servers` and `skills`) and `model_runtimes` (each runtime's `kind` and its `models`), read with
`GET .../devices/{device}` below. See [AI tool discovery](../discovery/ai-tool-discovery/) and
[MCP servers and skills](../discovery/mcp-and-skills/).

## AI fleet

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `GET` | `https://foobar.cvyuh.com/api/v0/endpoint/aig/v1/api/v1/overview` | The fleet at a glance: `total_devices`, `online_devices`, `offline_devices`, `config_failures`, `active_revision`, and the most recent devices | [Fleet records](../fleet/fleet-records/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/endpoint/aig/v1/api/v1/devices` | Every approved device, with who approved it and its `installed_tools` | [Fleet records](../fleet/fleet-records/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/endpoint/aig/v1/api/v1/devices/{device}` | One device in full: `discoveries`, `model_runtimes`, `recent_events` and `programs` | [Fleet records](../fleet/fleet-records/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/endpoint/aig/v1/api/v1/devices/{device}` | Drop the device from the fleet only; answers `204` | [Fleet records](../fleet/fleet-records/) |

`{device}` is the fleet device id, the `id` in the fleet's device list; it isn't the device id on the realm's
[device records](../../endpoint-management/devices/device-records/). To take a device out of the realm, use
[Device removal](../../endpoint-management/revoke-and-remove/removal/), which drops it from the fleet too.

## Configuration

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `GET` | `https://foobar.cvyuh.com/api/v0/endpoint/aig/v1/api/v1/daemon-config` | The configuration the realm gives its devices' AI tools agents, as `config`; `null` until managed configuration arrives | [What's next for configuration](../configuration/whats-next/) |

## Models

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `GET` | `https://foobar.cvyuh.com/api/v0/endpoint/aig/v1/api/v1/usage` | Model usage by user, device, tool, provider and model; empty until usage is collected | [What's next for models](../models/whats-next/#usage-and-cost) |

`usage` takes `range` (`24h`, `7d` by default, `30d` or `90d`), `by` (a comma-separated list of `user`, `device`,
`tool`, `provider` and `model`), `user`, `device`, `tool`, `provider` or `model` to narrow it, and `utcOffsetMinutes`
(from -840 to 840, `0` by default) for where daily totals begin. An unknown range, breakdown or offset answers `400`.

## Answers and errors

| Answer | Why |
|---|---|
| `204` | A device dropped |
| `400` | A usage query with an unknown `range`, `by` or `utcOffsetMinutes` |
| `401` | No session, or it has ended |
| `403` | Your privileges don't read this realm's configuration |
| `404` | `device not found`: no device in the realm's fleet has that id |
| `500` | The fleet couldn't read its records; try again |
