Start
Authentication
Sessions and keys#
| Browser session | API key | |
|---|---|---|
| Sent as | The cp_session cookie (HTTP-only) | Authorization: Bearer cpk_… |
| Who | A guest, or a wallet signed in with SIWE | An agent runtime or backend |
| Workspace | The active one; switch with POST /api/orgs/switch | Fixed: the workspace that created it |
| Permissions | The member's role (owner, admin, member, viewer) | Its scopes; never more than the workspace allows |
| Lifetime | 30 days | Until it expires or is revoked |
Browser sessions#
GET /api/session/guest?next=/app starts a guest session with its own sandbox workspace. Guests can do everything in their sandbox except keep it: a guest workspace is removed seven days after it was created.
Signing in with a wallet from a guest session keeps the sandbox. A new wallet takes over the guest account in place; a wallet that already has an account receives the guest sandbox only if it has no sandbox of its own.
Sign-In with Ethereum#
Wallet sign-in uses EIP-4361. The wallet signs a plain message; nothing is sent on-chain and no gas is spent. Smart-contract wallets are verified through ERC-1271 / ERC-6492 on the chain named in the message (Elysium or HyperEVM).
import { createSiweMessage } from "viem/siwe";
// 1. A single-use nonce (valid 10 minutes)
const { nonce } = await fetch("/api/auth/nonce", { method: "POST" }).then((r) => r.json());
// 2. An EIP-4361 message for this exact site
const message = createSiweMessage({
domain: window.location.host, // must equal the host serving CortexPay
uri: window.location.origin, // must start with this origin
address, // the connected wallet
chainId: 999, // HyperEVM; 99901 for Elysium
nonce,
version: "1",
statement: "Sign in to CortexPay",
issuedAt: new Date(),
});
// 3. The wallet signs it (personal_sign); no transaction, no gas
const signature = await walletClient.signMessage({ account: address, message });
// 4. CortexPay verifies it and sets the session cookie
await fetch("/api/auth/verify", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message, signature }),
});- The message's
domainmust equal the host serving CortexPay and itsurimust start with that origin; otherwise the sign-in is refused. - Each nonce works once, for 10 minutes.
- The session cookie is HTTP-only and lasts 30 days. Manage sessions in Settings → Security.
API keys#
Owners and admins create keys in Developer Console → API keys. A key has a name, scopes, an optional expiry, an optional application and a per-minute rate limit (10–600, default 120).
- The secret (
cpk_test_…orcpk_live_…) is shown once. CortexPay stores its SHA-256 hash and a short prefix, so a lost key cannot be recovered, only replaced. - Revoking is immediate and audited: the next request with that key gets
401. - Scopes are fixed when a key is created. To change them, create a new key and revoke the old one.
const res = await fetch("https://cortexpay.vercel.app/api/me", {
headers: { Authorization: `Bearer ${process.env.CORTEXPAY_API_KEY}` },
});
const me = await res.json();
console.log(me.org.name, me.org.mode, me.apiKey?.scopes);Scopes#
| Scope | Allows |
|---|---|
agents:read | List agents and read their accounts, transactions and budgets. |
agents:write | Register, pause, resume and revoke agents. |
policies:read | Read spending policies and past evaluations. |
policies:write | Create and change spending policies and run dry-run evaluations. |
payments:read | Read payments, service requests, approvals and network activity; verify settlement. |
payments:write | Request paid services, quote and authorize payments. |
services:read | List and read services in the marketplace. |
services:write | Register and update services as a provider. |
analytics:read | Read expenditure analytics and the workspace overview. |
webhooks:write | Register, update, test and delete webhook endpoints and read their deliveries. |
ai:use | Ask the AI assistant. Each question spends infrastructure credits. |
A request without the scope a route needs gets 403 with code: "forbidden" and a message naming the missing scope. A few read endpoints need no scope (for example GET /api/me and GET /api/credits/balance).
What keys cannot do#
Some actions always need a person in a signed-in session, so an agent holding a key can never widen its own powers:
- Approve or reject a payment that is waiting for approval.
- Resume a paused agent, fund it, withdraw from it, or freeze the workspace.
- Create, list or revoke API keys; manage applications, members or workspace settings.
- Register or re-validate a marketplace service (these need the owner or admin role, which keys do not carry).
Roles in a session
Owners do everything, including members and roles. Admins manage agents, policies, approvals, keys and webhooks. Members can request paid services within policies and read everything. Viewers are read-only.
Endpoints#
- GET
/api/session/guestStart a guest session with a seeded sandbox workspace, then redirect to ?next=.
Public
- POST
/api/auth/nonceSingle-use nonce for a Sign-In with Ethereum message (valid 10 minutes).
Public
- POST
/api/auth/verifyVerify a signed SIWE message { message, signature } and start a wallet session (cookie).
Public
- POST
/api/auth/logoutRevoke the current session and clear the cookie.
Public
- GET
/api/meThe caller, the active workspace and which platform features are configured.
Any key
- POST
/api/orgs/switchMake another of your workspaces active for this session.
Any key · Only meaningful for sessions; a key is bound to one workspace.
- GET
/api/keysAPI keys in the active workspace (prefix only).
Session
- POST
/api/keysCreate a key { name, scopes, expiresInDays?, applicationId?, rateLimitPerMin? }. The secret is returned once.
Session · owner/admin · 20/min
- GET
/api/keys/:idOne key (prefix, scopes, last use).
Session
- PATCH
/api/keys/:idRename or change the per-minute limit. Scopes are fixed.
Session · owner/admin · 60/min
- DELETE
/api/keys/:idRevoke now (audited). The next request with the key gets 401.
Session · owner/admin · 60/min
- GET
/api/applicationsRegistered applications with key and webhook counts.
Session
- POST
/api/applicationsRegister an application { name, description? }.
Session · owner/admin · 20/min
- GET
/api/applications/:idOne application.
Session
- PATCH
/api/applications/:id{ name?, description?, status? }. Disabling revokes its keys and disables its webhooks.
Session · owner/admin · 60/min
- DELETE
/api/applications/:idDelete an application that never had a key.
Session · owner/admin