Entrypoints
Entrypoints are typed API endpoints that define your agent's capabilities. Each entrypoint has input/output schemas, a handler, and optional pricing.
Defining an Entrypoint
Use addEntrypoint() from your framework adapter:
import { z } from 'zod';
import { createAgent } from '@regent/core';
import { http } from '@regent/http';
import { createAgentApp } from '@regent/hono';
const agent = await createAgent({
name: 'my-agent',
version: '1.0.0',
})
.use(http())
.build();
const { app, addEntrypoint } = await createAgentApp(agent);
addEntrypoint({
key: 'greet',
description: 'Greets a user by name',
input: z.object({
name: z.string(),
}),
output: z.object({
message: z.string(),
}),
async handler({ input }) {
return {
output: {
message: `Hello, ${input.name}!`,
},
};
},
});EntrypointDef Type
Input and Output Schemas
Schemas are defined with Zod and provide:
Runtime validation - Invalid inputs return 400 errors
TypeScript inference - Full type safety in handlers
JSON Schema generation - Automatic schema in Agent Card
Handler Function
Handler Signature
AgentContext
The context object passed to handlers:
Handler Example
Streaming Entrypoints
For long-running operations or LLM responses, use streaming:
Stream Handler Signature
Stream Envelope Types
The emit() function accepts these envelope types:
Full StreamEnvelope Union
Invoking Entrypoints
Non-Streaming (invoke)
Response:
Streaming (stream)
Response (SSE):
Adding Pricing
Entrypoints can require payment via the x402 protocol:
Or with separate invoke/stream pricing:
With payments configured, requests without valid payment headers return 402 Payment Required.
Usage Tracking
Return usage from handlers to track resource consumption:
Listing Entrypoints
Response:
Validation Errors
Invalid input returns a 400 error with details:
Best Practices
Use descriptive keys - The key appears in URLs and the Agent Card
Always add descriptions - They help with discovery and documentation
Validate thoroughly - Use Zod's built-in validators (
.min(),.max(),.email(), etc.)Stream when appropriate - Use streaming for LLM responses or long operations
Track usage - Return
usagefor billing and analyticsHandle errors gracefully - Throw errors with clear messages; they're returned as JSON
Next Steps
Packages: @regent/core - Core package reference
Packages: @regent/x402 - Monetize your entrypoints
Last updated