Skip to main content
Every SDK client requires two values: the base URL of your AgentRail API and a bearer token that proves the client’s identity. Both values are generated when you run agentrail init or agentrail agent create and are written to ~/.agentrail/agent.env.

Load credentials from the env file

The generated file looks like this:
Source it in your shell before running your harness:
When you have a hosted AgentRail API, replace the base URL with that address. The AGENTRAIL_API_KEY value stays the same.

The bearer token vs the key ID

Use the ar_live_... value as your API key. Values that start with akey_ are key IDs used for rotation and usage reporting — they are not bearer tokens and will not authenticate requests.

Construct the client

baseUrl is required by the constructor. Passing it explicitly avoids a hidden dependency on local defaults.

Auth errors

Auth scopes

Agent keys are scoped. Assign only the scopes your harness needs.
auth:admin is for bootstrap and administration only. Do not grant it to normal worker harnesses.

Idempotency keys

Mutating calls — submitTask, shipTask, createApiKey, and subscription creation — require an idempotency key. Reusing the same key with the same request body is safe and will return the original response. Reusing a key with a different body returns a 409 Conflict. Include the operation, task ID, and attempt identifier to keep keys unique:
Use a new key for each genuinely new attempt.