Defining a procedure
Procedures are created by chaining methods on theos builder and terminating with .handler().
.input(schema)
Defines the input validation schema. oRPC supports any Standard Schema-compatible library (Zod, Valibot, ArkType, etc.).
When you call
.input(), the schema is validated before the handler runs. If validation fails, oRPC returns a typed INPUT_VALIDATION_FAILED error automatically..output(schema)
Defines the output validation schema. The return type of the handler is checked against this schema at runtime.
.handler(fn)
The terminal method that provides the implementation. The handler receives a single options object:
| Property | Type | Description |
|---|---|---|
input | Inferred from schema | Validated, parsed input |
context | Current context type | Context enriched by middleware |
errors | ORPCErrorConstructorMap | Typed error constructors |
meta | Meta type | Procedure metadata |
path | string[] | The path segments of this procedure |
procedure | Procedure | The procedure object itself |
signal | AbortSignal | undefined | AbortSignal for cancellation |
.errors(map)
Registers typed, structured errors that the procedure can throw. This information flows to the client as typed errors and is included in the OpenAPI spec.
.meta(object)
Attaches arbitrary metadata to the procedure. Metadata is available in middleware and can be used for authorization, rate-limiting labels, or OpenAPI tags.
$meta<T>() call on the builder sets the meta shape for the entire builder tree.
.route(options)
Attaches HTTP routing information used by OpenAPI and adapters. Without a .route() call, the procedure is addressable via its router path.
.use(middleware)
Procedures can have middleware attached directly. See the Middleware page for full details.
Chaining order
The order of.input(), .output(), .errors(), .meta(), and .route() does not affect runtime behavior — they can appear in any order before .handler(). However, .use() calls are order-sensitive because they define the middleware execution order.
DecoratedProcedure extras
After calling .handler(), you get back a DecoratedProcedure which has two additional capabilities:
