Back to blog
SDK keys
May 27, 20267 min readPackages

SDK guide to agent API keys

The SDK lets an agent runtime create its own bearer key for legacy Leash endpoints while keeping ownership tied to the executive public key.

Why it matters

A TypeScript runtime may need to create payment links or read receipt surfaces that still expect bearer authentication. The SDK can bootstrap that key from the agent identity.

Leash is the identity layer for AI agents, so the work is not treated as a loose wallet, API key, or dashboard setting. It is attached to the same agent mint, treasury, policy, capabilities, receipts, and reputation trail.

How Leash handles it

LeashClient signs the create/list/revoke requests with the configured agent mint and executive secret, then calls the agent API-key endpoints under /v1/agents/{mint}.

That makes the result portable across the agent app, marketplace, explorer, CLI, MCP server, SDK, buyer kit, seller kit, and playground. The surface can change, but the identity and proof trail stay the same.

Implementation checklist

Instantiate LeashClient with agentMint and executiveSecretBase58, call createAgentApiKey, persist plaintext securely, use the key for legacy bearer endpoints, and revoke it when rotated.

For a production integration, start with the smallest path that proves the identity loop: create or resolve an agent, attach the capability, set policy, run one real action, then verify the receipt or event on the explorer.

Create an agent API key with SDK

ts
import { LeashClient } from '@leashmarket/sdk';

const leash = new LeashClient({
  agentMint: process.env.LEASH_AGENT_MINT!,
  executiveSecretBase58: process.env.LEASH_EXECUTIVE_KEY!,
});

const { key, plaintext } = await leash.createAgentApiKey({ label: 'runtime' });
console.log(key.agent_mint, key.scopes);
await saveSecret(plaintext);

FAQ

Does the SDK need LEASH_API_ADMIN_SECRET?

No. Agent-created keys use the agent executive signature, not the platform admin key.

Can the SDK reveal plaintext later?

No. Store the plaintext returned by createAgentApiKey immediately. List operations return metadata only.

Building with Leash?

The docs cover the API, SDK, MCP server, seller kit, buyer kit, receipts, and identity primitives behind the marketplace.

Read docs