Skip to main content
The @agentdoor/core configuration system uses Zod for runtime validation with strict type safety. This reference covers the complete AgentDoorConfig schema and all available options.

AgentDoorConfig

The main configuration object passed to AgentDoor initialization.
import { AgentDoorConfig } from "@agentdoor/core";

const config: AgentDoorConfig = {
  scopes: [
    {
      id: "weather.read",
      description: "Read weather data",
      price: "$0.001/req",
      rateLimit: "1000/hour"
    }
  ],
  storage: { driver: "sqlite", url: "./agentdoor.db" },
  x402: {
    network: "base",
    currency: "USDC",
    paymentAddress: "0x..."
  }
};

Required Fields

scopes
ScopeDefinition[]
required
Array of available scopes that agents can request. At least one scope must be defined.

Storage Configuration

storage
StorageConfig
Storage backend configuration. Defaults to in-memory storage.

Rate Limiting

rateLimit
RateLimitConfig
Default rate limit applied to new agents. Defaults to 1000 requests per hour.
registrationRateLimit
RateLimitConfig
Rate limit for the registration endpoint itself. Defaults to 10 registrations per hour.

x402 Payment Protocol

x402
X402Config
x402 payment protocol configuration. If not provided, payment features are disabled.

JWT Configuration

jwt
JwtConfig
JWT token settings for agent authentication.

Cryptographic Signing

signing
SigningConfig
Cryptographic signing algorithm configuration.

Service Metadata

service
ServiceConfig
Service metadata for discovery documents.

Companion Protocols

companion
CompanionConfig
Auto-generate endpoints for companion protocols.

Other Configuration

pricing
Record<string, string>
Global pricing map. Scope ID to price string.Example: { "weather.read": "$0.001/req" }
challengeExpirySeconds
number
Challenge expiry duration in seconds. Defaults to 300 (5 minutes).
mode
'live' | 'test'
API key mode. Affects the prefix of generated API keys.
  • live: Keys prefixed with agk_live_
  • test: Keys prefixed with agk_test_
Defaults to "live".

Callbacks

onAgentRegistered
(agent: Agent) => void | Promise<void>
Callback invoked when an agent successfully completes registration.
onAgentRegistered: async (agent) => {
  console.log(`Agent registered: ${agent.id}`);
  await notifySlack(`New agent: ${agent.metadata.name}`);
}
onAgentAuthenticated
(agent: Agent) => void | Promise<void>
Callback invoked when an agent successfully authenticates.
onAgentAuthenticated: async (agent) => {
  console.log(`Agent authenticated: ${agent.id}`);
  await updateMetrics(agent.id);
}

Validation Functions

validateConfig

Validates an AgentDoorConfig object against the Zod schema.
import { validateConfig } from "@agentdoor/core";

const config = { /* ... */ };
const validated = validateConfig(config);
config
unknown
required
Configuration object to validate.
returns
AgentDoorConfig
The validated configuration object.
Throws: InvalidConfigError if validation fails with detailed error messages.
try {
  validateConfig({ scopes: [] }); // Invalid: empty scopes
} catch (error) {
  console.error(error.message);
  // "Configuration validation failed:
  //   - scopes: At least one scope must be defined"
}

resolveConfig

Validates and resolves an AgentDoorConfig, applying all default values.
import { resolveConfig } from "@agentdoor/core";

const config = {
  scopes: [{ id: "api.read", description: "Read API" }]
};

const resolved = resolveConfig(config);
// Returns ResolvedConfig with all defaults applied:
// - storage: { driver: "memory" }
// - rateLimit: { requests: 1000, window: "1h" }
// - jwt.secret: auto-generated
// - etc.
config
AgentDoorConfig
required
Configuration object to resolve.
returns
ResolvedConfig
Configuration with all defaults applied. No optional fields (except x402).

Configuration Examples

Minimal Configuration

const config: AgentDoorConfig = {
  scopes: [
    { id: "api.read", description: "Read access" }
  ]
};

Production Configuration

const config: AgentDoorConfig = {
  scopes: [
    {
      id: "weather.read",
      description: "Read weather forecast data",
      price: "$0.001/req",
      rateLimit: "5000/hour"
    },
    {
      id: "weather.write",
      description: "Submit weather observations",
      price: "$0.005/req",
      rateLimit: "100/hour"
    }
  ],
  storage: {
    driver: "postgres",
    url: process.env.DATABASE_URL
  },
  x402: {
    network: "base",
    currency: "USDC",
    paymentAddress: process.env.WALLET_ADDRESS!,
    facilitator: "https://x402.org/facilitator"
  },
  rateLimit: {
    requests: 10000,
    window: "1h"
  },
  jwt: {
    secret: process.env.JWT_SECRET,
    expiresIn: "24h"
  },
  service: {
    name: "Weather API",
    description: "Professional weather data for AI agents",
    docsUrl: "https://api.weather.com/docs",
    supportEmail: "[email protected]"
  },
  mode: "live",
  onAgentRegistered: async (agent) => {
    await analytics.track("agent_registered", {
      agentId: agent.id,
      scopes: agent.scopesGranted
    });
  }
};

Development Configuration

const config: AgentDoorConfig = {
  scopes: [
    { id: "api.read", description: "Read access" },
    { id: "api.write", description: "Write access" }
  ],
  storage: { driver: "memory" },
  mode: "test",
  rateLimit: {
    requests: 100000,
    window: "1h"
  }
};

Build docs developers (and LLMs) love