Installation
Quick Start
AgentDoor Class
The main entry point for the SDK. Manages keypairs, discovers services, registers agents, and returns authenticated sessions.Constructor Options
Example: Basic Setup
Example: Ephemeral Agent
Example: x402 Wallet
Methods
connect(url: string): Promise<Session>
Connects to an AgentDoor-enabled service. Performs discovery, registration (if needed), and returns an authenticated session.
Parameters:
url— Base URL of the service (e.g.https://api.example.com)
Session object for making authenticated requests
Example:
Check Cache
Looks for cached credentials for this service. If valid credentials exist, skips to step 5.
publicKey: string
Returns the agent’s Ed25519 public key in base64 format.
Session Class
Represents an authenticated connection to a service. Created byagent.connect() and used to make API requests.
Properties
HTTP Methods
All methods return aSessionResponse<T> with the following shape:
get<T>(path: string, options?: RequestOptions): Promise<SessionResponse<T>>
post<T>(path: string, options?: RequestOptions): Promise<SessionResponse<T>>
put<T>(path: string, options?: RequestOptions): Promise<SessionResponse<T>>
delete<T>(path: string, options?: RequestOptions): Promise<SessionResponse<T>>
patch<T>(path: string, options?: RequestOptions): Promise<SessionResponse<T>>
Request Options
Example: Custom Headers
Example: Paid Request
Keystore Functions
Low-level functions for managing Ed25519 keypairs. Most users won’t need these directly — theAgentDoor class handles keypair management automatically.
generateKeypair(): Keypair
Generate a fresh Ed25519 keypair.
saveKeypair(keypair: Keypair, filePath: string): void
Save a keypair to disk as JSON.
loadKeypair(filePath: string): Keypair | null
Load a keypair from disk. Returns null if the file doesn’t exist.
loadOrCreateKeypair(filePath: string): Keypair
Load an existing keypair from disk, or generate and save a new one if none exists.
signMessage(message: string, secretKey: Uint8Array): string
Sign a message with an Ed25519 secret key. Returns a base64-encoded signature.
verifySignature(message: string, signature: string, publicKey: Uint8Array): boolean
Verify an Ed25519 signature.
Discovery Functions
discover(baseUrl: string, options?: DiscoverOptions): Promise<AgentDoorDiscoveryDocument>
Fetch and parse the AgentDoor discovery document from a service.
clearDiscoveryCache(baseUrl?: string): void
Clear the in-memory discovery cache. If baseUrl is provided, only that entry is cleared. Otherwise, the entire cache is cleared.
Credential Store
Manages per-service credentials on disk. Used internally byAgentDoor but can be used directly for advanced use cases.
CredentialStore
x402 Payment Functions
buildPaymentHeader(walletConfig: X402WalletConfig, context: RequestContext): string
Build an X-PAYMENT header value for a request. Returns a base64-encoded JSON payload.
buildSignedPaymentHeader(walletConfig, context): Promise<string>
Build a signed X-PAYMENT header with cryptographic proof from the wallet.
decodePaymentHeader(headerValue: string): X402PaymentPayload
Decode a base64-encoded X-PAYMENT header back to a payload object. Useful for debugging.
Error Handling
AgentDoorError
Thrown when agent operations fail (discovery, registration, authentication).NO_MATCHING_SCOPES— No requested scopes match what the service offersINVALID_REGISTER_RESPONSE— Registration response is malformedINVALID_VERIFY_RESPONSE— Verification response is malformedINVALID_AUTH_RESPONSE— Auth response is malformedALREADY_REGISTERED— Agent already registered (HTTP 409)RATE_LIMITED— Too many requests (HTTP 429)CHALLENGE_EXPIRED— Challenge nonce expired (HTTP 410)HTTP_ERROR— Generic HTTP errorNETWORK_ERROR— Network request failedTIMEOUT— Request timed outINVALID_JSON— Response body is not valid JSON
SessionError
Thrown when session requests fail.Advanced Usage
Custom Fetch Function
Inject a custom fetch implementation for testing or special transport requirements:Multiple Services
Connect to multiple services with a single agent:Requesting Specific Scopes
Next Steps
Python SDK
Build agents in Python with async/await support
Examples
See complete agent implementations including LangChain integration