AgentDoor makes your API agent-ready in 3 lines of code. This guide shows you how to integrate AgentDoor into your server and connect to it from an agent.
For SaaS Owners
Add AgentDoor to your existing API to enable headless agent registration, authentication, and payments.
Install AgentDoor
Choose your framework: npm install @agentdoor/express
Add the middleware
const express = require ( "express" );
const agentdoor = require ( "@agentdoor/express" );
const app = express ();
// Add AgentDoor middleware
app . use ( agentdoor ({
scopes: [
{ id: "data.read" , description: "Read data" , price: "$0.001/req" },
{ id: "data.write" , description: "Write data" , price: "$0.01/req" }
],
rateLimit: { default: { requests: 1000 , window: "1h" } },
x402: {
network: "base" ,
currency: "USDC" ,
paymentAddress: "0xYourWallet..."
}
}));
// Your existing API routes — now agent-ready
app . get ( "/api/data" , ( req , res ) => {
if ( req . isAgent ) {
console . log ( `Agent ${ req . agent . id } requesting data` );
}
res . json ({ data: "hello" });
});
app . listen ( 3000 );
Your API is now agent-ready
AgentDoor automatically creates these endpoints:
/.well-known/agentdoor.json — Discovery endpoint
/agentdoor/register — Agent registration
/agentdoor/register/verify — Challenge verification
/agentdoor/auth — Token refresh
Your existing routes now have agent context in req.agent when called by agents.
For Agent Developers
Connect your AI agent to any AgentDoor-enabled service in under 500ms.
Install the SDK
npm install @agentdoor/sdk
Connect and authenticate
import { AgentDoor } from "@agentdoor/sdk" ;
const agent = new AgentDoor ({
keyPath: "~/.agentdoor/keys.json" , // auto-generates keypair if needed
x402Wallet: "0x1234...abcd" // optional: x402 wallet as identity
});
// Discover + register + auth in ONE call
const session = await agent . connect ( "https://api.example.com" );
Make authenticated requests
// Make authenticated + paid requests
const data = await session . get ( "/weather/forecast" , {
params: { city: "sf" },
x402: true // auto-attach x402 payment header
});
console . log ( data . data );
Using the CLI
AgentDoor provides a CLI for quick setup and configuration:
Auto-generate from OpenAPI
Interactive setup
Generate agent keypair
npx agentdoor init --from-openapi ./openapi.yaml
The CLI will:
Analyze your API structure
Generate AgentDoor configuration
Add middleware to your framework
Set up scopes and pricing
The CLI generates production-ready configuration based on your OpenAPI spec, making integration even faster.
Complete Example
Here’s a complete end-to-end example with both server and agent:
Server (Express)
Agent (TypeScript)
Agent (Python)
const express = require ( "express" );
const agentdoor = require ( "@agentdoor/express" );
const app = express ();
app . use ( agentdoor ({
scopes: [
{ id: "weather.read" , description: "Read weather data" , price: "$0.001/req" }
],
rateLimit: { default: { requests: 1000 , window: "1h" } }
}));
app . get ( "/weather/forecast" , ( req , res ) => {
const { city } = req . query ;
if ( req . isAgent ) {
console . log ( `Agent ${ req . agent . id } requesting weather for ${ city } ` );
}
res . json ({
city ,
temperature: 72 ,
conditions: "sunny"
});
});
app . listen ( 3000 , () => {
console . log ( "Server running on http://localhost:3000" );
});
import { AgentDoor } from "@agentdoor/sdk" ;
async function main () {
const agent = new AgentDoor ({
keyPath: "~/.agentdoor/keys.json"
});
// Connect to the service (discover + register + auth)
const session = await agent . connect ( "http://localhost:3000" );
// Make authenticated request
const weather = await session . get ( "/weather/forecast" , {
params: { city: "san-francisco" }
});
console . log ( "Weather:" , weather . data );
}
main ();
import asyncio
from agentdoor import Agent
async def main ():
agent = Agent()
# Connect to the service
await agent.connect( "http://localhost:3000" )
# Make authenticated request
response = await agent.request( "GET" , "/weather/forecast" , params = { "city" : "san-francisco" })
print ( "Weather:" , response.json())
await agent.close()
asyncio.run(main())
What Happens Under the Hood
When agent.connect() is called:
Discovery (~50ms): Agent fetches /.well-known/agentdoor.json to learn about available scopes, pricing, and endpoints
Registration (~100ms): Agent sends public key and requested scopes to /agentdoor/register, receives a challenge nonce
Challenge-Response (~200ms): Agent signs the nonce with its private key, server verifies and issues JWT + API key
Ready (~150ms): Total time from start to authenticated
Total: <500ms vs 30-60s for browser automation.
Next Steps
Core Concepts Learn how AgentDoor works under the hood
Server Integration Framework-specific integration guides
Agent SDK Build agents that connect to services
Configuration Advanced configuration options