# API keys Keys for apps, scripts and agents. Each has one scope; a read or trade key can be limited to some accounts. The full key is shown once, when you create it. ### List keys `GET /api/v1/keys` Scope: admin. Every key, newest first. The full key is never shown again; `prefix` helps you tell them apart. **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Keys. A JSON array of ApiKey. | Field | Type | Description | |---|---|---| | `id` | string | Key id, used to revoke it. (required) | | `name` | string | What the key is for. (required) | | `prefix` | string | The key's first 12 characters (tl_ and 9 more), to recognise it. (required) | | `scopes` | array of string | One scope. (required; one of read, trade, admin) | | `accounts` | array or null | Account ids the key may use. null = every account. (required) | | `created_at` | integer | Unix seconds (UTC). (required) | | `last_used_at` | integer or null | Unix seconds (UTC) of the last request, null if never used. (required) | | `max_volume` | number or null | The most lots one order that opens something may have (0.6.0); null: no limit. (required) | | `max_open_per_min` | integer or null | The most orders that open something this key may send in 60 s (0.6.0); null: no limit. (required) | | `max_daily_loss` | number or null | The most the account may lose in a forex day (from 17:00 New York, account currency) before this key opens nothing (0.7.0); null: no limit. (required) | | `max_drawdown_pct` | number or null | The most percent the account's equity may fall below its high since the limit was set before this key opens nothing (0.7.0); null: no limit. (required) | | `limits_since` | integer or null | When the drawdown limit was set, unix milliseconds; its high counts from then (0.7.0). (required) | Example: ```json [ { "id": "key_3f9a1c07", "name": "EA bridge (gold)", "prefix": "tl_4be1a09c7", "scopes": [ "trade" ], "accounts": [ "pepperstone-12345678" ], "created_at": 1790709498, "last_used_at": 1790974298, "max_volume": 0.5, "max_open_per_min": 10, "max_daily_loss": 500.0, "max_drawdown_pct": null, "limits_since": null } ] ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/keys" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/keys", headers=auth) r.raise_for_status() print(r.json()) ``` ### Create a key `POST /api/v1/keys` Scope: admin. Pick one scope: `read` (prices and account state), `trade` (read plus orders) or `admin` (everything, including accounts, keys, servers and diagnostics). Limit a read or trade key to some accounts with `accounts`; an admin key cannot be limited (400). Keys look like `tl_` and 48 hex characters; only a SHA-256 hash is stored, so the response is the only time the full `key` appears. **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Request body** (ApiKeyCreate) | Field | Type | Description | |---|---|---| | `name` | string | What the key is for, for example "EA bridge (gold)". Up to 80 characters. (required) | | `scopes` | one of | Exactly one scope. trade includes read; admin includes everything. Defaults to ["read"]. | | `accounts` | array of string | Limit the key to these account ids. Omit for every account. Not allowed with admin (400); an unknown id is 400 too. | | `max_volume` | number | The most lots one order that opens something may have; above it the order answers 403 key_limit and is not sent. Closing is never limited. Omit for no limit (0.6.0). | | `max_open_per_min` | integer | The most orders that open something this key may send in 60 s, 1 to 600; past it 429 key_limit with Retry-After, not sent. Omit for no limit (0.6.0). | | `max_daily_loss` | one of | A positive amount in the account's currency; past it (from the forex day's start) orders that open something answer 403 key_limit, not sent (0.7.0). null or left out: no limit. | | `max_drawdown_pct` | one of | More than 0, at most 100: past that many percent below the equity's high since it was set, orders that open something answer 403 key_limit, not sent (0.7.0). Setting or changing it starts its high afresh. | Example: ```json { "name": "EA bridge (gold)", "scopes": [ "trade" ], "accounts": [ "pepperstone-12345678" ], "max_volume": 0.5, "max_open_per_min": 10 } ``` **Response 201**: Created. Store key now. A ApiKeyCreated object. | Field | Type | Description | |---|---|---| | `id` | string | Key id, used to revoke it. (required) | | `name` | string | What the key is for. (required) | | `prefix` | string | The key's first 12 characters (tl_ and 9 more), to recognise it. (required) | | `scopes` | array of string | One scope. (required; one of read, trade, admin) | | `accounts` | array or null | Account ids the key may use. null = every account. (required) | | `created_at` | integer | Unix seconds (UTC). (required) | | `last_used_at` | integer or null | Unix seconds (UTC) of the last request, null if never used. (required) | | `max_volume` | number or null | The most lots one order that opens something may have (0.6.0); null: no limit. (required) | | `max_open_per_min` | integer or null | The most orders that open something this key may send in 60 s (0.6.0); null: no limit. (required) | | `max_daily_loss` | number or null | The most the account may lose in a forex day (from 17:00 New York, account currency) before this key opens nothing (0.7.0); null: no limit. (required) | | `max_drawdown_pct` | number or null | The most percent the account's equity may fall below its high since the limit was set before this key opens nothing (0.7.0); null: no limit. (required) | | `limits_since` | integer or null | When the drawdown limit was set, unix milliseconds; its high counts from then (0.7.0). (required) | | `key` | string | The full key, tl_ and 48 hex characters. It is shown only in this response, so store it now. (required) | Example: ```json { "id": "key_3f9a1c07", "name": "EA bridge (gold)", "prefix": "tl_4be1a09c7", "scopes": [ "trade" ], "accounts": [ "pepperstone-12345678" ], "created_at": 1790981179, "last_used_at": null, "max_volume": 0.5, "max_open_per_min": 10, "max_daily_loss": 500.0, "max_drawdown_pct": null, "limits_since": null, "key": "tl_4be1a09c7d2e5f8b1a3c6e9d0f2b4a7c8e1d3f5a7b9c0e2d" } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. **curl** ```sh curl -s -X POST "$TERMLESS_URL/api/v1/keys" \ -H "Authorization: Bearer $TERMLESS_KEY" \ -H "Content-Type: application/json" \ -d '{"name": "EA bridge (gold)", "scopes": ["trade"], "accounts": ["pepperstone-12345678"], "max_volume": 0.5, "max_open_per_min": 10}' ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.post(f"{base}/keys", headers=auth, json={ "name": "EA bridge (gold)", "scopes": [ "trade" ], "accounts": [ "pepperstone-12345678" ], "max_volume": 0.5, "max_open_per_min": 10 }) r.raise_for_status() print(r.json()) ``` ### Edit a key `PATCH /api/v1/keys/{id}` Scope: admin. Change a key's name, scope or accounts in place (0.6.0). The key itself and its id stay the same, so nothing that holds it has to change. Every request sees the change at once; a stored Idempotency-Key answer is not replayed to a key that may no longer trade on its account (403); a stream it opened on an account it may no longer read ends with reason key changed. Audited (kind key, route update). **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Key id. | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Request body** (ApiKeyUpdate) Any of the fields; the ones left out stay as they are (0.6.0). | Field | Type | Description | |---|---|---| | `name` | string | A new name, up to 80 characters. | | `scopes` | one of | Exactly one scope, as on create. | | `accounts` | one of | The account ids it may use; null or [] for every account. Not allowed with admin (400); an unknown id is 400 too. | | `max_volume` | one of | The most lots per order that opens something; null for no limit. | | `max_open_per_min` | one of | The most orders that open something in 60 s, 1 to 600; null for no limit. | | `max_daily_loss` | one of | A positive amount in the account's currency; past it (from the forex day's start) orders that open something answer 403 key_limit, not sent (0.7.0). null or left out: no limit. | | `max_drawdown_pct` | one of | More than 0, at most 100: past that many percent below the equity's high since it was set, orders that open something answer 403 key_limit, not sent (0.7.0). Setting or changing it starts its high afresh. | Example: ```json { "scopes": [ "trade" ], "accounts": [ "pepperstone-12345678" ] } ``` **Response 200**: The key as listed (the secret is never shown again). A ApiKey object. | Field | Type | Description | |---|---|---| | `id` | string | Key id, used to revoke it. (required) | | `name` | string | What the key is for. (required) | | `prefix` | string | The key's first 12 characters (tl_ and 9 more), to recognise it. (required) | | `scopes` | array of string | One scope. (required; one of read, trade, admin) | | `accounts` | array or null | Account ids the key may use. null = every account. (required) | | `created_at` | integer | Unix seconds (UTC). (required) | | `last_used_at` | integer or null | Unix seconds (UTC) of the last request, null if never used. (required) | | `max_volume` | number or null | The most lots one order that opens something may have (0.6.0); null: no limit. (required) | | `max_open_per_min` | integer or null | The most orders that open something this key may send in 60 s (0.6.0); null: no limit. (required) | | `max_daily_loss` | number or null | The most the account may lose in a forex day (from 17:00 New York, account currency) before this key opens nothing (0.7.0); null: no limit. (required) | | `max_drawdown_pct` | number or null | The most percent the account's equity may fall below its high since the limit was set before this key opens nothing (0.7.0); null: no limit. (required) | | `limits_since` | integer or null | When the drawdown limit was set, unix milliseconds; its high counts from then (0.7.0). (required) | Example: ```json { "id": "key_3f9a1c07", "name": "EA bridge (gold)", "prefix": "tl_4be1a09c7", "scopes": [ "trade" ], "accounts": [ "pepperstone-12345678" ], "created_at": 1790709498, "last_used_at": 1790974298, "max_volume": 0.5, "max_open_per_min": 10, "max_daily_loss": 500.0, "max_drawdown_pct": null, "limits_since": null } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. **curl** ```sh curl -s -X PATCH "$TERMLESS_URL/api/v1/keys/key_3f9a1c07" \ -H "Authorization: Bearer $TERMLESS_KEY" \ -H "Content-Type: application/json" \ -d '{"scopes": ["trade"], "accounts": ["pepperstone-12345678"]}' ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.patch(f"{base}/keys/key_3f9a1c07", headers=auth, json={ "scopes": [ "trade" ], "accounts": [ "pepperstone-12345678" ] }) r.raise_for_status() print(r.json()) ``` ### Revoke a key `DELETE /api/v1/keys/{id}` Scope: admin. The key stops working at once, its traffic in the connections view is dropped, and the streams it opened end (reason key revoked). **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Key id. | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 204**: Revoked. **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. **curl** ```sh curl -s -X DELETE "$TERMLESS_URL/api/v1/keys/key_3f9a1c07" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.delete(f"{base}/keys/key_3f9a1c07", headers=auth) r.raise_for_status() # 204, no body ```