Start

Authentication

People use CortexPay through a browser session. Agents and servers use API keys. Both act inside one workspace, and both are checked on every request.
Code samples in

Sessions and keys#

Browser sessionAPI key
Sent asThe cp_session cookie (HTTP-only)Authorization: Bearer cpk_…
WhoA guest, or a wallet signed in with SIWEAn agent runtime or backend
WorkspaceThe active one; switch with POST /api/orgs/switchFixed: the workspace that created it
PermissionsThe member's role (owner, admin, member, viewer)Its scopes; never more than the workspace allows
Lifetime30 daysUntil 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).

Browser
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 }),
});
  1. The message's domain must equal the host serving CortexPay and its uri must start with that origin; otherwise the sign-in is refused.
  2. Each nonce works once, for 10 minutes.
  3. The session cookie is HTTP-only and lasts 30 days. Manage sessions in Settings → Security.
CortexPay never asks for a seed phrase or private key
Signing in is a signature over a readable message. No CortexPay page, email or assistant will ever ask for a recovery phrase or key.

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_… or cpk_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#

ScopeAllows
agents:readList agents and read their accounts, transactions and budgets.
agents:writeRegister, pause, resume and revoke agents.
policies:readRead spending policies and past evaluations.
policies:writeCreate and change spending policies and run dry-run evaluations.
payments:readRead payments, service requests, approvals and network activity; verify settlement.
payments:writeRequest paid services, quote and authorize payments.
services:readList and read services in the marketplace.
services:writeRegister and update services as a provider.
analytics:readRead expenditure analytics and the workspace overview.
webhooks:writeRegister, update, test and delete webhook endpoints and read their deliveries.
ai:useAsk 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/guest

    Start a guest session with a seeded sandbox workspace, then redirect to ?next=.

    Public

  • POST/api/auth/nonce

    Single-use nonce for a Sign-In with Ethereum message (valid 10 minutes).

    Public

  • POST/api/auth/verify

    Verify a signed SIWE message { message, signature } and start a wallet session (cookie).

    Public

  • POST/api/auth/logout

    Revoke the current session and clear the cookie.

    Public

  • GET/api/me

    The caller, the active workspace and which platform features are configured.

    Any key

  • POST/api/orgs/switch

    Make another of your workspaces active for this session.

    Any key · Only meaningful for sessions; a key is bound to one workspace.

  • GET/api/keys

    API keys in the active workspace (prefix only).

    Session

  • POST/api/keys

    Create a key { name, scopes, expiresInDays?, applicationId?, rateLimitPerMin? }. The secret is returned once.

    Session · owner/admin · 20/min

  • GET/api/keys/:id

    One key (prefix, scopes, last use).

    Session

  • PATCH/api/keys/:id

    Rename or change the per-minute limit. Scopes are fixed.

    Session · owner/admin · 60/min

  • DELETE/api/keys/:id

    Revoke now (audited). The next request with the key gets 401.

    Session · owner/admin · 60/min

  • GET/api/applications

    Registered applications with key and webhook counts.

    Session

  • POST/api/applications

    Register an application { name, description? }.

    Session · owner/admin · 20/min

  • GET/api/applications/:id

    One 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/:id

    Delete an application that never had a key.

    Session · owner/admin