OpenAPI Callback Objects: connect a callback URL to a request
An OpenAPI Callback Object describes a later request associated with an initial API request. For example, a client supplies a notification URL in its request and the provider POSTs to it when work is ready. The callback happens because of that initial request. Use the top-level OpenAPI webhooks field to describe provider-initiated events that are independent of another API call.
An OpenAPI Callback Object describes a later request associated with an initial API request. For example, a client supplies a notification URL in its request and the provider POSTs to it when work is ready. The callback happens because of that initial request. Use the top-level OpenAPI webhooks field to describe provider-initiated events that are independent of another API call.
Callback Object structure
Each Callback Object key is a runtime expression evaluated against an HTTP request or response. Its result identifies the URL the API provider will call. Each value is a Path Item Object that describes the callback method, request body, and expected responses.
paths:
/reports:
post:
operationId: createReport
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [callbackUrl]
properties:
callbackUrl:
type: string
format: uri
callbacks:
reportReady:
'{$request.body#/callbackUrl}':
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ReportReady'
responses:
'200':
description: Callback processed
responses:
'202':
description: Report request acceptedThis YAML is illustrative and was not validated. reportReady names the Callback Object; {$request.body#/callbackUrl} extracts the URL at runtime. The callback operation follows the ordinary Operation Object structure. OpenAPI describes the contract; it does not send the callback.
Read the runtime expression
$request.body#/callbackUrl reads the callbackUrl property from the current request body using JSON Pointer. The expression is wrapped in braces as the callback map key. Runtime expressions can access request/response URL, method, status, headers, and body values. Define service behavior for a missing value or expression evaluation failure.
If users provide callback URLs, merely describing them in OpenAPI does not make them safe. Validate the URL and destination before the server makes a network request, and restrict calls to permitted targets. OWASP identifies custom callback URLs as an SSRF risk and discusses allowlists, network controls, redirect handling, and destination validation at connection time. Choose controls based on which destinations the service must support.
Request-linked callback vs independent webhook
| Callback Object | Top-level webhooks | |
|---|---|---|
| Trigger | Tied to a specific API operation request | Independent provider-initiated request |
| URL | Can be derived from a runtime expression | Describes incoming message shape in the API document |
| Location | Operation Object callbacks | OpenAPI Object webhooks |
| Example | Completion notice to a URL supplied with a report request | Event delivery declared by the API |
This distinction models request direction and trigger in the OpenAPI document. Authentication, signatures, retries, timeouts, deduplication, and subscription changes still need a service contract.
Design review
Choose whether the callback belongs to one request or is an independent webhook.
Document the callback name, URL expression, and actual HTTP request separately.
Define callback body, success/error responses, and permitted methods.
If the URL comes from the caller, design SSRF defenses and review destination validation and redirects.
Specify authentication/signing, retry schedule, duplicate event identity, expiry, and cancellation.
Verify that your OpenAPI parser and docs tool support Callback Objects and runtime expressions.
OpenAPI documents the callback contract; it does not implement delivery, security checks, or retries. No API, callback server, or specification tool was run for this article.
Sources
[OpenAPI Specification 3.2.1: Callback Object](https://spec.openapis.org/oas/v3.2.1.html#callback-object)
[OpenAPI Specification 3.2.1: Webhooks](https://spec.openapis.org/oas/v3.2.1.html#oas-webhooks)
[OWASP: Server-Side Request Forgery Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html)