Skip to main content
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.
1

Install AgentDoor

Choose your framework:
npm install @agentdoor/express
2

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);
3

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.
See framework-specific guides: Express, Next.js, Hono, Fastify, FastAPI

For Agent Developers

Connect your AI agent to any AgentDoor-enabled service in under 500ms.
1

Install the SDK

npm install @agentdoor/sdk
2

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");
3

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:
npx agentdoor init --from-openapi ./openapi.yaml
The CLI will:
  1. Analyze your API structure
  2. Generate AgentDoor configuration
  3. Add middleware to your framework
  4. 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:
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");
});

What Happens Under the Hood

When agent.connect() is called:
  1. Discovery (~50ms): Agent fetches /.well-known/agentdoor.json to learn about available scopes, pricing, and endpoints
  2. Registration (~100ms): Agent sends public key and requested scopes to /agentdoor/register, receives a challenge nonce
  3. Challenge-Response (~200ms): Agent signs the nonce with its private key, server verifies and issues JWT + API key
  4. 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

Build docs developers (and LLMs) love