Skip to main content
Molecule enforces two distinct authentication modes because trading operations and account management carry different trust models. Trading routes require cryptographic proof that the request originated from a process holding a registered private key — no shared secret or session token can substitute. Management routes (account configuration, org-level controls) require a human session JWT issued through the Molecule dashboard. Passing the wrong credential to either class of endpoint produces a hard error, not a silent fallback.

Trading Key Authentication (Ed25519)

Every trading request is authenticated by an Ed25519 signature computed locally in your process. The flow is:
  1. You generate an Ed25519 keypair and register the public key with Molecule.
  2. For each request, the SDK computes a canonical string from the HTTP method, path, sorted query parameters, timestamp, and SHA-256 body hash.
  3. The SDK signs that string with your private key and attaches three headers to the outgoing request.
Your private key never leaves your process. Molecule only stores the public key and uses it to verify the signature on arrival.

Signing headers

The SDK attaches all three headers automatically whenever you construct a client with key_id and private_key. You do not need to compute or attach them yourself.

Initialize the client with a trading key

Pass your key_id and private_key directly to the Molecule constructor. The base_url is required — set it via the MOLECULE_BASE_URL environment variable or pass it explicitly.

Accepted private key formats

The SDK’s load_private_key function accepts the following representations of a 32-byte Ed25519 seed: The canonical format is base64 of the 32-byte seed, matching what the key-generation snippet in Key Management produces. Use that format for all stored credentials.

JWT Token Authentication (Management Routes)

Account management routes — such as configuring organizations, managing users, and accessing dashboard-level resources — require a JWT issued by the Molecule platform. Pass the token to the token= parameter of the constructor. The SDK sends it as an Authorization: Bearer <token> header.
The two authentication modes are not interchangeable. Using a trading key (Ed25519) on a management route returns 403 human_session_required. Using a JWT token on a trading route returns 401 unauthorized. There is no automatic fallback.
Do not pass both private_key and token to the same client instance. When both are present, the SDK prioritises Ed25519 signing and ignores the token. Use separate client instances for trading and management operations.

Error reference

The table below maps error codes to their Python exception class and the remediation action.

Next steps

Key Management

Generate an Ed25519 keypair, export the seed in the canonical base64 format, and load it securely in your process.

Request Signing

Understand the canonical string construction, replay protection, and WebSocket signing in detail.