# Call the agent API over REST

A harness that calls HTTP can use the Valakes agent API on 127.0.0.1. Read the port and token from files, check the server's proof, then send the token.

Source: https://valakes.com/agents/rest-api/

Last updated: 2026-11-24

A harness that calls HTTP directly can use the same tools as the MCP bridge, under /v1 on 127.0.0.1. It must check that the server is Valakes before it sends its token.

## What a REST harness gets

A harness that speaks HTTP gets the agent tools as routes under `/v1`, the same tools and the same results as over MCP. That suits a model wired to function calling through your own code, where starting an MCP bridge is not the natural fit. The routes are listed below and in `/v1/openapi.json`.

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

## Set it up

Your harness must do what the bridge does, in this order, before it sends the token. Do not skip the proof: the port changes at every start, and a process that binds the port after Valakes stops would receive a token sent without checking. That token controls what the agent may do on your servers.

1. Turn on Settings, Agent API, then create the agent with Connect an agent and choose REST.

2. Read `api.json` in Valakes' data folder for the port and the instance id. Refuse the file unless it is yours alone (on Windows, unless it is inside that folder).

   ```
   %APPDATA%\ValakesApp\api.json
   ~/Library/Application Support/ValakesApp/api.json
   ```

3. Read the token from `agents/<handle>.token` in the same folder, with the same check.

4. Call hello with no Authorization header:

   ```
   GET /v1/hello?agent=<handle>&nonce=<64 random hex characters>
   ```

5. Check that `instance_id` equals the one in `api.json`, and that `proof` equals:

   ```
   base64url(HMAC-SHA256(SHA-256(token), "valakes-server-v1" || nonce || instance_id))
   ```

6. Only then send `Authorization: Bearer <token>`, and only on that same connection.

The connection wizard in Valakes shows this setup, with your own paths and handle.

The OpenAPI document lists the same steps under `x-valakes-handshake`. The `/mcp` endpoint takes the same bearer token and is protected the same way.

## Two practical notes

The server refuses any request that has an `Origin` header or a `Sec-Fetch-*` header, which is what a browser sends. Node's built-in `fetch` adds `Sec-Fetch-Mode`, so a Node client uses `node:http`, as the bridge does. Requests must name the host exactly as `127.0.0.1` with the port; `localhost` is refused.

A tool that waits for an approval can take minutes. The connection stays open until you answer or the request expires, so give your client a long enough timeout.

## Check that it works

The first call that needs the token is the real test. `GET /v1/hosts` with the bearer header should return the hosts you opened to agents and nothing more. `GET /v1/guide` returns the agent guide as Markdown, which your harness can hand to its model. The connection wizard's Test connection shows the first call from Valakes' side.

If `/v1/hello` gives a proof that does not match, stop. "The server could not prove itself" means the program at the port did not know your token. Do not work around it: check that Valakes is the process running, restart it, and if it persists rotate the agent's token and treat the file as exposed.

## What it can and cannot do

The REST routes are the MCP tools under another name, so a harness gets no extra power by calling HTTP itself. The server checks the host header, refuses anything a browser would send, and reads the token only from the `Authorization` header. Every call then passes the same policy, risk check and approval as an MCP call.

### It can

- Call every tool the MCP bridge offers, as REST routes
- Read the agent guide at `/v1/guide`
- Read the OpenAPI document at `/v1/openapi.json`
- Use saved passwords through `{{cred:name}}`
- Wait on one open connection while an approval is pending

### It cannot

- Send a request from a browser
- Use any host name but `127.0.0.1` and the port
- Pass the token in the query string, a cookie or the body
- Read a credential, approve a request or read the audit log

## Host policy and approvals

Calls to a host at Off answer as if the host did not exist, and a new host always starts there. On Approve writes a call that is not a read command stays open while its card waits in your approval queue. When you approve, Valakes runs the command it recorded, so the harness cannot swap the command afterwards.

## Documentation

[Read the docs: REST API](https://docs.valakes.com/agents/rest-api/)

## Read next

- [AI agents work under your rules](https://valakes.com/features/ai-agents/): Valakes has a local API that lets an AI agent such as Claude Code or Codex open sessions and run commands on the hosts you allow. The agent never sees a password, and changes wait for your approval.
- [Dangerous commands wait for you](https://valakes.com/features/command-check/): The command check reads each command you type before it runs. A dangerous one stops on a card that says why, and it runs only when you choose.
