codai docs
API referenceGateway

Hosts

The relay that lets a phone run an operation on your desktop: presence stream, exec and result.

A host is a device that keeps GET /v1/hosts/stream open. Another device posts an exec; the gateway relays it over that stream and blocks until the host posts the result or the timeout fires. Presence expires 45 s after the last heartbeat. This relay is best-effort and not part of the public sessions protocol spec. Walkthrough: hosts guide.

Agents see which hosts are online through the MCP server tool hosts_list (read-only; exec is not exposed over MCP).

GET
/v1/hosts

Authorization

bearerAuth
headerAuthorizationBearer <codai_…>

A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).

Header Parameters

x-request-id?string

Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.

Lengthlength <= 128

Response Body

Connected hosts.

application/json
  1. response
hosts*array<>
Example Request
curl -X GET 'https://ai.codai.ro/v1/hosts'
Example Response
{  "hosts": [    {      "device_id": "2b6d8c1e-4f3a-4e9b-9c0d-7a1e5f6b8c2d",      "name": "codai desktop",      "platform": "desktop",      "os": "windows",      "hostname": "dragos-desktop",      "roots": [        "E:\\gh",        "C:\\Users\\me\\Projects"      ],      "caps": [        "iphone",        "video"      ],      "environment_id": "7c1e2d3f-4a5b-4c6d-8e9f-0a1b2c3d4e5f",      "since": 1758616800000,      "last_seen": 1758616845000    }  ]}
GET
/v1/hosts/stream

Authorization

bearerAuth
headerAuthorizationBearer <codai_…>

A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).

Query Parameters

os?string

Host operating system label; truncated to 40 chars.

Lengthlength <= 40
hostname?string

Host machine name; truncated to 120 chars.

Lengthlength <= 120
roots?string

Comma-separated list of filesystem roots the host exposes; blanks dropped, max 32 entries.

caps?string

Comma-separated capabilities the host offers (iphone, video, pty, …); at most 16 entries, each matching ^[a-z0-9_-]{1,32}$, duplicates dropped. A malformed list is a 400.

env?string

UUID of the environment that serves video / pty streams for this host over codai-relay. Not a uuid → 400.

Formatuuid

Header Parameters

x-request-id?string

Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.

Lengthlength <= 128
x-codai-device*string

Stable device UUID. Registers the device on first use (name/platform from x-codai-device-name / x-codai-device-platform) and selects the shared-sessions protocol.

Formatuuid

Response Body

SSE stream (text/event-stream, cache-control: no-cache).

response?stringtext/event-stream
Example Request
curl -X GET 'https://ai.codai.ro/v1/hosts/stream' \  -H 'x-codai-device: 497f6eca-6276-4993-bfeb-53cbbbba6f08'
Example Response
"string"
POST
/v1/hosts/{deviceId}/exec

Authorization

bearerAuth
headerAuthorizationBearer <codai_…>

A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).

Path Parameters

deviceId*string

Device UUID of the target host (from GET /v1/hosts).

Formatuuid

Header Parameters

x-request-id?string

Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.

Lengthlength <= 128
x-codai-device*string

Stable device UUID. Registers the device on first use (name/platform from x-codai-device-name / x-codai-device-platform) and selects the shared-sessions protocol.

Formatuuid

Request Body

application/json
  1. body
op*HostOp

Operation vocabulary hosts implement (codai desktop; iphone = the codai iPhone bridge, cap iphone).

Value in"shell""fs_read""fs_write""fs_list""fs_roots""info""iphone"
args?

Op-specific arguments, relayed verbatim (e.g. { cmd, cwd?, timeout_ms? } for shell, { path } for fs_list). For iphone they must match HostIphoneArgs ({ tool, args? }), else 400.

Default{}
timeout_ms?integer

How long to wait for the host. Default 60000.

Range1000 <= value <= 600000
label?string

Free-form label shown in the host UI.

Lengthlength <= 200

Response Body

The host answered (whether ok is true or false).

application/json
  1. response
req_id*string
Formatuuid
ok*boolean
result*unknown

The host's result, or null when absent.

error*string|null
Example Request
curl -X POST 'https://ai.codai.ro/v1/hosts/497f6eca-6276-4993-bfeb-53cbbbba6f08/exec' \  -H 'x-codai-device: 497f6eca-6276-4993-bfeb-53cbbbba6f08' \  -H 'Content-Type: application/json' \  -d '{  "op": "shell"}'
Example Response
{  "req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",  "ok": true,  "result": null,  "error": "string"}
POST
/v1/hosts/exec/{reqId}/result

Authorization

bearerAuth
headerAuthorizationBearer <codai_…>

A codai API key (codai_ prefix). Ephemeral tokens from POST /v1/tokens are accepted only by the media surfaces matching their scope (/v1/realtime, /v1/audio/*, /v1/embeddings).

Path Parameters

reqId*string

The req_id from the exec event (UUID; malformed → 400).

Formatuuid

Header Parameters

x-request-id?string

Client correlation id; echoed back as x-codai-trace-id and persisted on the usage row.

Lengthlength <= 128
x-codai-device*string

Stable device UUID. Registers the device on first use (name/platform from x-codai-device-name / x-codai-device-platform) and selects the shared-sessions protocol.

Formatuuid

Request Body

application/json
  1. body
ok*boolean

Whether the op succeeded on the host.

result?unknown

Any JSON produced by the op (e.g. { stdout, stderr, exit_code } for shell); relayed as-is. Shape is defined by the desktop, not the gateway.

error?string

Human-readable failure reason when ok is false.

Lengthlength <= 4000

Response Body

Accepted.

application/json
  1. response
ok*true
Value intrue
Example Request
curl -X POST 'https://ai.codai.ro/v1/hosts/exec/497f6eca-6276-4993-bfeb-53cbbbba6f08/result' \  -H 'x-codai-device: 497f6eca-6276-4993-bfeb-53cbbbba6f08' \  -H 'Content-Type: application/json' \  -d '{  "ok": true}'
Example Response
{  "ok": true}

Last updated: