🔐Authentication
All Molecule APIs require authentication. This page covers how to obtain credentials, which headers each API expects, and the specific authentication model for the Labs API.
Obtaining API Access
All Molecule APIs require authentication with an API key. To request access:
Join our Discord community
Contact the Molecule team with your use case
You'll receive:
API Key - Required for all APIs
Service Token - Additional token for Labs API (if needed)
Authentication Headers
Labs API (queries)
x-api-key
x-api-key: YOUR_API_KEY
Labs API (mutations, service token)
x-api-key
X-Service-Token
x-api-key: YOUR_API_KEY
X-Service-Token: YOUR_SERVICE_TOKEN
Labs API (mutations, Privy user)
x-api-key
Authorization
x-wallet-address
x-api-key: YOUR_API_KEY
Authorization: Bearer PRIVY_TOKEN
x-wallet-address: 0x…
Tokenization API
x-api-key
x-api-key: YOUR_API_KEY
IPNFT API (Deprecated)
x-api-key
x-api-key: YOUR_API_KEY
Labs API Authentication
The Labs API has different authentication requirements depending on the operation type:
Rule of thumb: Most queries are public (API Key only). Write mutations are authenticated, and most accept either a Service Token or a Privy user session — pick whichever fits your caller. The exceptions are called out below: one query is gated, the two Service Token lifecycle mutations are service-token-only, and
generateServiceTokenbootstraps a token with a Privy session or wallet signature.
Summary of the model:
Most queries are public: API Key only for read operations. Exception:
legalAgreementTemplaterequires a Service Token or an authenticated session.Write mutations are authenticated, with two interchangeable paths: API Key plus either
X-Service-Token(machine callers — services, bots, agents) orAuthorization+x-wallet-address(Privy user session — browser and app callers). Authorization is then evaluated against the caller's identity either way.Exceptions:
extendServiceTokenandrevokeServiceTokenaccept only a Service Token.generateServiceTokenaccepts only a Privy session or wallet signature, since it mints the token in the first place.Service Token: Identifies which specific lab/dataroom you have write access to.
File-level access control is handled via Molecule's Onchain-Verified Envelope Encryption, not query authentication — see Data Privacy & Access.
Public Queries (Read-Only)
These queries are public and only require an API Key:
labs- List all labs with paginationlabWithDataRoomAndFiles- Get lab details and fileslabActivity- Get activity feed for a lab, (available filters: ANNOUNCEMENT | FILE)activities- Get global activity feed, (available filters: ANNOUNCEMENT | FILE)dataRoomFile- Get file by pathsearchLabs- Search across labs, files, and announcementsfileCategoriesAndTags- List valid file categories and their tagsgetServiceSignInMessage- Get the message a service signs to obtain a tokengetDidLinkStatus- Get background DID-linking status for a lablegalAgreementStatus- Check whether a lab's legal agreement is signedonChainActivity- Onchain event feed for a lab or walletlistLabMembers- List a lab's members
Authenticated query — API Key plus a Service Token, or an authenticated user session:
legalAgreementTemplate- Get the populated agreement to sign (the signer's authenticated session, or a service token)
Protected Mutations (Write Operations)
All write mutations require an API Key plus proof of caller identity. For most mutations there are two interchangeable ways to prove identity — the resolver accepts a Service Token if one is present, and otherwise falls back to authenticating the Privy user:
Option 1 — Service Token (services, bots, agents, CI/CD):
Option 2 — Privy user session (browser and app callers acting as a signed-in user):
Either way, the caller still has to be authorized for the target lab — a Service Token carries its own lab scope, and a Privy session is checked against the wallet's onchain role (LabNFT owner, authorized multisig signer, or an active role on AccessResolver). Supplying neither returns a NO_AUTH error naming both paths.
Mutations accepting either path:
createLab- Create a lab (data room) for an onchain lab (OCL) · 💳 also available pay-per-call via x402 GatewayinitiateCreateOrUpdateFile- Initiate file upload · 💳 also available pay-per-call via x402 GatewayfinishCreateOrUpdateFile- Complete file upload · 💳 also available pay-per-call via x402 GatewayupdateFileMetadata- Update file metadatadeleteDataRoomFile- Delete a filecreateAnnouncement- Create an announcement · 💳 also available pay-per-call via x402 GatewayupdateLabNftMetadata- Update LabNFT display metadata (OCL admin only)generateLabImageUploadUrl- Get a presigned URL to upload a LabNFT image (OCL admin only)signLegalAgreement- Record acceptance of a legal agreementgenerateDataEncryptionKey- Generate a standalone data encryption key · 💳 also available pay-per-call via x402 GatewaydecryptDataKey- Decrypt a file's data key for an authorized caller · 💳 also available pay-per-call via x402 Gateway
Service-Token-only mutations — these manage token lifecycle and reject Privy sessions:
extendServiceToken- Extend service token expirationrevokeServiceToken- Revoke a service token
generateServiceTokenis the bootstrap exception, in the opposite direction: it mints a Service Token, so it accepts only an API Key plus either a Privy session or a wallet signature — not a pre-existing Service Token. See Obtaining Tokens.
Pay-per-call alternative. Mutations tagged 💳 above can also be called through the x402 Gateway, which settles a USDC payment on Base per request and mints a short-lived service token on the fly — no long-lived credentials required. Useful for autonomous AI agents and third-party tools that pay for users.
Obtaining API Key and Service Token
To obtain access credentials:
Join our Discord community
Contact the Molecule team and provide:
Your wallet address (will be linked to the service token)
Intended use case / service name
Which lab/dataroom you need access to
Desired token expiration period
The team will generate and provide you with:
API Key - Used for all Molecule APIs
Service Token (JWT string) - Grants access to specific lab
Token ID - For management operations
Using Your Credentials
For all queries (read-only operations):
For mutations (write operations) — as a service:
For mutations — as a signed-in user (accepted by all mutations except extendServiceToken and revokeServiceToken):
Why more than one header for mutations?
API Key: Authenticates you as a valid Molecule API user
Service Token: Identifies which specific lab/dataroom your service has write access to
Privy token + wallet address: Identifies the human caller instead, whose write access is derived from their wallet's onchain role
Which path to choose: use a Service Token for unattended callers (backends, bots, agents, CI/CD) where there is no user session to draw on. Use the Privy path when a signed-in user is driving the request, so the action is attributed to their wallet and governed by their onchain role rather than a shared service credential.
Security Warnings:
Service tokens are shown only once during generation - store them securely immediately
Never commit tokens or API keys to version control
Never log credentials in application logs
Store in environment variables or secure secret management systems
Rotate tokens regularly (quarterly recommended)
Service Token lifecycle operations (extending, revoking) are documented in Service Tokens.
Last updated