Skip to content
Valakes docs
Menu

REST API

What this is for: The agent REST API

Last updated

On this page

A harness that calls HTTP directly, such as one built on function calling, can use the same ten tools that MCP clients get. The server runs on your computer, on 127.0.0.1 and a port that the operating system picks every time Valakes starts. It is off until you turn it on in Settings, Agent API, and create an agent as described on the Claude Code page.

Prove the server before you send the token

Section titled “Prove the server before you send the token”

A harness must do what the bridge does, in this order, before the token leaves its process.

  1. Open api.json in the data folder of Valakes. It holds the port and the instance id. The folder is %APPDATA%\ValakesApp on Windows and ~/Library/Application Support/ValakesApp on macOS. Do not use the file unless it is yours alone; on Windows it must lie inside that folder.
  2. Read the token from agents/<handle>.token in the same folder, with the same check.
  3. Call GET /v1/hello?agent=<handle>&nonce=<64 random hex characters> with no Authorization header. Check that instance_id equals the one in api.json, and that proof equals the value of this formula:
base64url(HMAC-SHA256(SHA-256(token), "valakes-server-v1" || nonce || instance_id))
  1. Only then send the header Authorization: Bearer <token>, and only on that same connection.

Do not skip the proof. The port changes at every start, and a process that binds it after Valakes stops would receive your token if you sent it unchecked. The token controls what the agent may do on your servers. The OpenAPI document at /v1/openapi.json lists the same steps under x-valakes-handshake.

Each tool is one route. The OpenAPI document at /v1/openapi.json describes every one of them in full.

Method Path Tool
GET /v1/hosts list_hosts
POST /v1/sessions open_session
DELETE /v1/sessions/{session_id} close_session
POST /v1/sessions/{session_id}/commands run_command
GET /v1/blocks/{block_id}/output read_output
GET /v1/sessions/{session_id}/screen get_screen
POST /v1/sessions/{session_id}/keys send_keys
GET /v1/hosts/{host_id}/credentials list_credentials
POST /v1/sessions/{session_id}/uploads upload_file
POST /v1/sessions/{session_id}/downloads download_file

GET /v1/guide returns the built-in guide as Markdown and needs the agent’s token like every other route. GET /v1/hello and GET /v1/openapi.json need none.

The server is built so that a web page cannot call it, and so a mistake in a harness fails closed.

  • A request with an Origin header or a Sec-Fetch- header is refused, which is what a browser sends. A Node client cannot use the built-in fetch, which adds Sec-Fetch-Mode by itself; use node:http, as the bridge does.
  • The Host header must be exactly 127.0.0.1:<port>. localhost is not accepted.
  • A POST needs Content-Type: application/json and a body of at most 256 KiB.
  • The token is read only from the Authorization: Bearer header, never from the query string, a cookie or the body.
  • A paused agent gets 423 with agent_paused, and a revoked or unknown token gets 401. Past the rate limit the answer is 429 with a Retry-After header. A call may wait for your approval for minutes, and the connection stays open while it does.

Errors come as { "error": { "code": "...", "message": "..." } } from a fixed catalogue. The limits that apply to a call are on how agents work: one command at a time per session, at most 4 at a time per agent, at most 5 open sessions per agent, and about 20 requests per second per agent.

The same server answers MCP on POST /mcp. It takes the same bearer token and sits behind the same checks, so a client that talks to it directly, and not through the bridge, must do the proof above first, on every connection. Most MCP clients should use the bridge, as on the pages for Claude Code and other MCP clients.

If the proof fails, the program at the port did not know your token. Do not work around it. Check that Valakes is the process that is running and restart it, and if the failure stays, rotate the agent’s token in the Agents panel and treat the old token file as exposed.