AgentRail / Developer guide
Booking API for AI agents
Use a provider-scoped bearer session to read booking requests and submit a service booking request. The examples below describe the existing AgentRail routes and their current response contracts.
01 / Access
Authentication and scope
Send Authorization: Bearer <token>. For provider access, the token must resolve to a signed-in user mapped to a provider account. Reads use that account’s provider ID; a query parameter cannot switch the provider scope. This API does not offer anonymous provider access, API-key authentication, or OAuth-client authentication.
A guest booking token is narrower: it can read only its bound booking through the detail route when the requested ID matches. It cannot list bookings or create one. Signed-in customer sessions, when used, are scoped to that customer’s own bookings; they do not receive the provider booking contract.
02 / Discover and read
Discover services and read provider bookings
GET/api/agent/services
Lists services only for the provider mapped to the bearer session. The provider must currently have online booking enabled, and each service must have an ai_agent permission set to allowed or requires_approval. Services requiring approval remain listable; a booking request for one waits for provider review. The response includes only service selector details, pricing rules, and intake requirements. It does not include provider profiles, permission records, customer data, or bookings. No provider ID is needed or accepted as scope; a mismatched providerId query value returns 403. An empty result is { "services": [] }.
GET /api/agent/services
Authorization: Bearer <provider-session-token>
{
"services": [
{
"id": "<service-id>",
"code": "<service-code>",
"title": "<service-title>",
"category": "<category>",
"description": "<public service description>",
"durationMinutes": 60,
"pricingRules": [
{
"kind": "flat",
"amountCents": 12500,
"unit": "visit",
"currency": "usd",
"minCents": null,
"notes": "Example pricing note"
}
],
"intakeRequirements": [
{
"id": "<requirement-id>",
"kind": "text",
"prompt": "What should the provider know before the visit?",
"required": false
}
],
"agentBookingMode": "requires_approval"
}
]
}GET/api/agent/bookings
Returns { "items": [...] } for the authenticated provider, newest first. An empty collection is { "items": [] }. You may pass one status filter:pending, approved, or declined. An invalid or repeated status filter returns 400. The route always applies the authenticated provider ID; a different providerId query value returns 403.
GET /api/agent/bookings?status=pending
Authorization: Bearer <provider-session-token>
{ "items": [] }GET/api/agent/bookings/{id}
Returns one provider booking object for an in-scope ID. An unavailable ID and an ID belonging to another provider both return 403 with { "error": "Forbidden" }.
GET /api/agent/bookings/{id}
Authorization: Bearer <provider-session-token>For GET /api/agent/services, missing, malformed, or invalid bearer credentials return 401. A signed-in customer or guest-booking principal has no provider scope and receives 403. The service list is read-only and never accepts a caller-selected provider scope.
03 / Booking object
Provider booking response
The detail response and provider-created response are a booking object, not a wrapper. It includes provider ( id, name, city, state), service ( id, title, category), customer contact and service-address fields, vehicle fields, symptoms,intakeResponses, photos, reply and decline fields, status, and timestamps. The requested, confirmed, and proposed start/end fields are nullable ISO date-time strings. Customer, address, vehicle, and reply details may also be null; intake responses may be null.
Status is pending, approved, declined, or reschedule_proposed. Stored approval-required requests are serialized as pending. Pending means a request is awaiting the next provider action; do not present it as a confirmed appointment.
{
"id": "<booking-id>",
"providerId": "<provider-id>",
"serviceId": "<service-id>",
"status": "pending",
"requestedWindowStartAt": "2099-09-10T15:00:00.000Z",
"requestedWindowEndAt": "2099-09-10T17:00:00.000Z",
"confirmedWindowStartAt": null,
"confirmedWindowEndAt": null,
"proposedWindowStartAt": null,
"proposedWindowEndAt": null,
"vehicleYear": null,
"vehicleMake": null,
"vehicleModel": null,
"mileage": null,
"symptoms": "Please inspect the service issue.\n\nIt started this morning.",
"customerName": "Morgan Example",
"customerEmail": "morgan@example.test",
"customerPhone": "555-010-0000",
"serviceAddressLine1": "123 Example Street, Sample City",
"serviceAddressLine2": null,
"serviceCity": null,
"serviceState": null,
"servicePostalCode": null,
"intakeResponses": [
{
"requirementId": "<service-requirement-id>",
"kind": "text",
"prompt": "Current service intake prompt",
"value": "It started this morning."
}
],
"declineReason": null,
"providerReply": null,
"providerReplyAt": null,
"photos": [],
"provider": {
"id": "<provider-id>",
"name": "Example Provider",
"city": "Sample City",
"state": "ST"
},
"service": {
"id": "<service-id>",
"title": "Example Service",
"category": "Example Category"
},
"createdAt": "2026-11-10T10:00:00.000Z",
"updatedAt": "2026-11-10T10:00:00.000Z"
}04 / Create
Submit a booking request
Send JSON to POST /api/agent/bookings. The request needs an Origin accepted by AgentRail and a UUID Idempotency-Key. Missing or untrusted Origin returns 403. The example uses placeholders: set APP_ORIGIN to an accepted app origin, replace the service and requirement IDs, and use sample customer values only in testing.
POST /api/agent/bookings
Authorization: Bearer <provider-session-token>
Origin: $APP_ORIGIN
Idempotency-Key: 11111111-1111-4111-8111-111111111111
Content-Type: application/json
{
"serviceId": "<service-id>",
"customerName": "Morgan Example",
"customerEmail": "morgan@example.test",
"customerPhone": "555-010-0000",
"address": "123 Example Street, Sample City",
"requestedWindowStartAt": "2099-09-10T15:00:00.000Z",
"requestedWindowEndAt": "2099-09-10T17:00:00.000Z",
"intakeNotes": "Please inspect the service issue.",
"intakeResponses": [
{ "requirementId": "<service-requirement-id>", "value": "It started this morning." }
],
"photos": []
}serviceId, customer name, email, phone,address,intakeNotes, and both requested window fields are required. The window must be future, include a UTC offset, and end after it starts.providerIdis optional. If supplied by a provider session, it must match that session’s provider. It cannot be used to select another provider.intakeResponsesis an optional array of{ requirementId, value }entries for this service’s intake requirements. Required answers and values are validated against the selected service.photosis an optional array of previously uploaded private-file references. Up to 6 JPEG, PNG, GIF, or WebP images are accepted, at 20 MB each. Each reference has the private-file fields{ key, filename, mime_type, size, created_at }. If the service requires diagnostic photos, include them or validation returns 400.- For an automotive service,
vehicleYear,vehicleMake,vehicleModel, andmileageare required. Other service types do not use those vehicle fields.
The selected service must belong to a provider with online booking enabled and have an ai_agent permission other than denied. A missing or denied permission returns 403; a service whose provider has online booking disabled returns 400. With requires_approval, creation submits a request for provider review and the response status is pending, not confirmed.
05 / Outcomes
Retries and errors
A newly created provider booking returns 201 with the booking object. Replaying the same request with the same key returns 200 with that same object. Reusing a key for a different request returns 409. Use a new UUID for each distinct request and retain the key when retrying an identical request.
401 { "error": "Unauthorized" }
400 { "error": "Invalid status filter." }
400 { "error": "A JSON request body is required." }
400 { "error": "The selected service is not available for online booking." }
400 { "errors": { "idempotencyKey": "A valid Idempotency-Key header is required." } }
400 { "errors": { "customerEmail": "Enter a valid email address" } }
403 { "error": "Forbidden" }
403 { "error": "Agent booking is not permitted for this service." }
403 { "error": "forbidden_origin" }
409 { "error": "This idempotency key was already used for a different booking request." }
500 { "error": "Could not load bookings right now." }
500 { "error": "Could not load this booking right now." }
500 { "error": "Could not create the booking right now." }- 401: missing or invalid bearer credentials.
- 400: invalid or repeated collection filter, malformed JSON, unavailable service, or field validation. Body validation uses
{ errors: { field: message } }; filter, JSON, and service errors use{ error: ... }. - 403: out-of-scope access, booking permission, or missing/untrusted Origin.
- 500: generic booking read or create failure.