@orpc/contract package lets you define the shape of your API (inputs, outputs, errors, routes) as a standalone contract, decoupled from any implementation. This supports contract-first development where the API surface is defined once and shared between server and client.
oc — the contract builder
oc is the root ContractBuilder instance.
Builder methods
.$meta<TMeta>(initialMeta)
Sets the initial metadata type for contract procedures.
.$route(initialRoute)
Sets the initial route definition for the builder.
.$input<TSchema>(initialSchema)
Sets the initial input schema.
.errors(errorMap)
Registers type-safe errors on the contract.
.meta(meta)
Sets or merges metadata.
.route(route)
Sets or merges route options.
.input(schema)
Defines the input validation schema for a contract procedure.
.output(schema)
Defines the output validation schema for a contract procedure.
.prefix(path)
Prefixes all procedures in a contract router with the given path.
.tag(...tags)
Adds OpenAPI tags to all procedures in a contract router.
.router(contractRouter)
Applies all accumulated options to a contract router.
Full contract example
ContractProcedure
Represents a single contract procedure definition.
ContractRouter
A recursive type representing either a ContractProcedure or a nested object of them.
Utility types
InferContractRouterInputs<T>
Infers all input types from a contract router.
InferContractRouterOutputs<T>
Infers all output types from a contract router.
InferContractRouterErrorMap<T>
Infers the union of all error maps from a contract router.
eventIterator()
Declares that a procedure’s input or output is an async event iterator (for SSE/streaming).
Implementing a contract
Once you have a contract, implement it withimplement() from @orpc/server:
