Skip to Content
NeurotraderDocs
Reference

Authentication

The access token every request carries, the header and websocket forms, device enrolment, the entitlement lease, and the status codes of a refused request.

Every request to the engine, except the health check, must prove who is asking. This page lists what a client sends, what the engine checks, and what comes back when the check fails. It also covers the two things that stand behind your account on a computer: the device enrolment and the entitlement lease.

Summary

CredentialAn access token of your Neurotrader account
On an HTTP requestAuthorization: Bearer <token>
On the websocket handshakeSec-WebSocket-Protocol: neurotrader.v1, auth.bearer.<token>
Route without a tokenGET /v1/health only
Token lifetimeAbout one hour
Missing or refused token401, with the cause in details.reason

Access token

There is exactly one credential: an access token issued for your Neurotrader account by the account's sign-in service (an Amazon Cognito user pool). It is a signed JSON Web Token.

The engine issues no credentials of its own. It has no login route, no API keys and no sessions. It verifies the token on each request and does not care which client obtained it. The desktop app has no special access: it signs you in, receives a token and sends it the same way a script does.

Checks

A token is accepted when all of these hold:

  • Its signature verifies against the sign-in service's published keys.
  • It was issued by the Neurotrader sign-in service.
  • It has not expired.
  • It is an access token. An ID token from the same sign-in is refused.
  • It was issued to a client application the engine accepts.

Lifetime

An access token lives for about one hour. The client is responsible for obtaining a fresh one before the old one expires, and for sending a valid one with every request.

A token gates requests, not work in progress. A run you started keeps running after the token that started it expires, and a websocket connection stays open. You need a valid token again for the next request.

Signing in needs the network, so a client that cannot reach the sign-in service cannot drive the engine once its token has expired.

Token for a script

A script signs in with your Neurotrader account, the same account you use in the app, and receives the same kind of token. It does not need a browser: the sign-in service also accepts a direct sign-in from a program, and libraries for it exist in most languages.

A script that runs for longer than an hour signs in again, or refreshes its token, before the token expires. A refused request with the reason expired_token is the signal that it waited too long.

Keep the token out of files you share and out of URLs. Anyone who holds it can drive your engine until it expires.

Authorization header

Send the token in the Authorization header with the Bearer scheme:

curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:8080/v1/runner

GET /v1/health is the only route that answers without it. It returns the engine's status and version, so a client can tell "the engine is not running" from "my token is refused".

curl http://127.0.0.1:8080/v1/health
{ "status": "ok", "time": "2026-03-02T09:14:07.512+00:00", "version": "0.1.0" }

Websocket handshake

A browser cannot set the Authorization header when it opens a websocket, so the realtime endpoint, /v1/events, also accepts the token in the Sec-WebSocket-Protocol header. Offer two values: the protocol name, neurotrader.v1, and the token prefixed with auth.bearer..

GET /v1/events HTTP/1.1
Host: 127.0.0.1:8080
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Protocol: neurotrader.v1, auth.bearer.<token>

In a browser:

const socket = new WebSocket("ws://127.0.0.1:8080/v1/events", [
  "neurotrader.v1",
  `auth.bearer.${accessToken}`,
])
  • The engine selects neurotrader.v1 and nothing else. The token is never echoed back.
  • A client that can set headers may send Authorization: Bearer <token> on the handshake instead. When both are present, Authorization is the one that counts.
  • The token is checked once, at the handshake. A refusal is an HTTP 401 before the upgrade, never a close frame.
  • An open connection is not closed when the token expires.

See Realtime updates for what the connection carries.

Browser clients

A script or a native program needs only a token. A page running in a browser is also held to an origin rule: the engine answers cross-origin requests, and accepts websocket handshakes, only from the origins on its allow-list. A websocket handshake from another origin is refused with 403 and the reason origin_not_allowed. A handshake that carries no Origin header, as from a script, is not judged by this rule.

Device enrolment

The engine on a computer is a device of your account, and each enrolled device uses one of the seats your plan includes. One installation is one device, however many clients drive it: the app, a script and a notebook on the same computer share the seat.

The app enrols the engine when you sign in. Over the API, the routes are:

RequestEffect
GET /v1/deviceReports whether this engine is enrolled, for which account, the account's plan and its devices.
POST /v1/deviceEnrols this engine and takes a seat. The body may carry a label, the name shown in your device list.
DELETE /v1/deviceRemoves the enrolment and releases the seat.
POST /v1/device/leaseObtains or refreshes the lease.

Each of these acts for the account the token belongs to.

  • When every seat is taken, enrolment is refused with 409, and the response lists the account's devices so you can release one.
  • A released seat does not become free at once. It goes through a waiting period first, so that one subscription cannot be passed from computer to computer.
  • An engine enrolled by one account refuses to be enrolled or released by another (enrolled_elsewhere).

See Subscription and devices.

Entitlement lease

The lease is a signed statement of what your plan allows on this device: the plan, its features and its limits. The engine obtains it from the Neurotrader licensing service, stores it and checks it without contacting any server.

You rarely handle the lease yourself. The engine obtains one, or refreshes one that is due, whenever a request that needs it arrives with a valid token: a run's start, a comparison's creation, a data download. POST /v1/device/lease does the same on demand and reports the plan and the two dates below. The lease itself is never returned by the API.

Features behind the lease

GatedRefusal
Creating or starting a comparison or an instrument sweep403 feature_not_in_plan
Starting or resuming a backtest beyond the number your plan runs at once429 concurrent_runs_exhausted
Starting a live run beyond the number your plan allows429 live_runners_exhausted
Starting a run on an engine that is not enrolled404 not_enrolled
Starting a run when the lease cannot be used409 lease_unusable
Reading the market data stored on your computerThe data is stored encrypted, and the lease carries the keys

Everything else, such as creating a single-account runner, editing it and reading results, needs only a valid token.

Lease dates

A lease has two dates, reported as expires_at and not_after:

  • After expires_at, about seven days from issue, the engine refreshes the lease the next time it can. Until it can, the old lease keeps working, so a short outage of the licensing service does not stop you.
  • After not_after, about thirty days from issue, the lease is no longer accepted, and gated actions are refused until a fresh one is obtained.

The engine can refresh the lease only while a signed-in client is talking to it, because the refresh uses that client's token. Open the app, or run a script with a valid token, from time to time on a computer you leave unattended.

A run in progress is not stopped by the lease. The limits apply to the next start.

Status codes

A refused request answers with the standard error envelope, described in Errors, and a details.reason you can branch on.

{
  "result": "Error",
  "message": "unauthorized: the token has expired",
  "details": { "reason": "expired_token" },
  "timestamp": "2026-03-02T10:31:44.902Z"
}
StatusCasedetails.reason
401No token was sentmissing_token
401The Authorization header is not a Bearer tokennot_bearer
401The token is not a well-formed JSON Web Tokenmalformed_token
401The token has expiredexpired_token
401The signature does not verify, or the signing key is unknowninvalid_signature, unknown_key, wrong_algorithm
401The token comes from another issuerinvalid_issuer
401The token is not an access tokenwrong_token_use
401The token was issued to a client application the engine does not acceptunknown_client
401The token is unacceptable for another reasoninvalid_token, anonymous_token
403A websocket handshake from a browser origin that is not allowedorigin_not_allowed
503The engine cannot fetch the sign-in service's keys to verify any tokenkey_source_unavailable

On expired_token, obtain a fresh token and send the request again. On 503, the fault is not in your token: try again shortly. The other reasons do not go away on a retry.

The full list of reason codes, including the ones for devices and the lease, is in Errors.

On this page