Extend AI Hub Checkout with API Extensions and webhooks to add custom validation, shipping logic, and fraud checks to your agentic commerce flows.
This extensibility model applies only to the Google AI Hub checkout module. It doesn't apply to the Stripe ACS module, which uses its own order import flow, or to the OpenAI module.
Extensibility model
commercetools provides two extensibility mechanisms that you can use independently or together.
API Extensions
API Extensions are:
- triggered within commercetools APIs on Carts and Orders
- channel-agnostic, working across all sales channels (storefronts, APIs, integrations)
- suitable for synchronous validation and enrichment
Typical use cases include:
- tax calculation
- external pricing
- validation logic
- Custom Field enrichment
- compliance rules
Conditional triggers
- run an extension only for agentic Stores
- apply different logic for standard storefronts and AI-driven checkout flows
store(key="my-agentic-store") restricts execution to Carts in a specific agentic Store.AI Hub webhook
The AI Hub webhook is:
- invoked during checkout lifecycle actions (create, update, read, complete)
- designed for agentic or channel-specific orchestration
- focused on real-time checkout decision-making
Typical use cases include:
- inventory checks that return errors specific to each agentic channel (for example, Google)
- delivery or shipping promise creation and stock reservation in a backend system for a specific channel
- fraud checks specific to an agentic channel based on request headers
When to use which
| Scenario | Recommended approach |
|---|---|
| Channel-agnostic logic (tax, pricing, validation) | API Extensions |
| Core commerce logic reused across all channels | API Extensions |
| Channel-specific variation of shared logic | API Extensions with conditional triggers |
| Agentic or AI-specific checkout orchestration | AI Hub webhook |
| Inventory checks with channel-specific error handling | AI Hub webhook |
| Stock reservation or delivery promise for a specific channel | AI Hub webhook |
| Final checkout validation in AI-driven flows | AI Hub webhook |
How they work together
When both mechanisms are active, they execute sequentially:
- The agent triggers a checkout session action (
CreateorUpdate). - commercetools creates or updates the Cart based on the request.
- API Extensions are triggered based on configured conditions and they run first to handle core Cart logic, such as taxes or pricing.
- If the Cart operation succeeds, AI Hub invokes the webhook, if configured, with the corresponding action (
Create,Update,Read, orComplete). The webhook handles external business logic that the Cart resource can't do, such as fraud checks or real-time inventory validation. - The external system evaluates the request.
- The webhook returns a response with validation results.
- AI Hub proceeds or blocks checkout based on the response.
Because execution is sequential, the two mechanisms cannot return conflicting results:
- If an API Extension blocks the Cart update, the process stops immediately and the webhook is never invoked. The agent receives an error and can retry.
- If the API Extension succeeds but the webhook returns a
Failureresponse, the Cart update is preserved, but the checkout session is flagged as incomplete. The agent is blocked from completing checkout until the issue is resolved (for example, by adjusting quantities or changing the shipping address). - If the webhook itself fails due to a server error or timeout, the system proceeds with checkout rather than blocking the shopper due to a technical issue.
Create, Update, Read, Complete). If your implementation needs to address multiple concerns (fraud, inventory), route internally within your endpoint. Different agentic channels can each have their own webhook configuration.AI Hub webhook reference
To use the AI Hub webhook, you build and host an HTTP endpoint that receives requests from AI Hub and returns structured responses. AI Hub acts as the caller: it sends an HTTP POST request to your endpoint at each checkout lifecycle stage. Your endpoint processes the request and returns a JSON response that tells AI Hub whether to proceed or block the checkout.
The following sections describe the contract between AI Hub and your endpoint, including configuration, request format, and expected response structure.
Configuration
Configure the webhook in the Merchant Center under the Checkout tab of the agentic channel. The following fields are available:
| Field | Description |
|---|---|
| Extension URL | The HTTPS URL of your webhook endpoint |
| Extension secret | The full value sent in the Authorization header of webhook requests, including the authentication scheme. The system injects this value as-is, without adding or removing a scheme prefix. Provide the complete header value, such as Bearer my-token or Basic <credentials>. The value must start with a valid scheme prefix, such as Bearer or Basic. |
| Extension timeout (ms) | Maximum time in milliseconds to wait for a response. Defaults to 10000 ms (10 seconds) |
Authentication
AI Hub injects the Extension secret value directly into the Authorization header of every webhook request. The system does not add a scheme prefix or perform any transformation, so the value you configure is sent exactly as written.
Authorization: <extension-secret-value>
Bearer my-token, configure the Extension secret as Bearer my-token. commercetools validates that the configured value starts with a valid scheme prefix, such as Bearer or Basic.Your endpoint must validate this value to confirm the request originates from AI Hub. Reject requests with missing or invalid authorization.
HTTPS is required for production endpoints. IP allowlisting and request signing are not supported.
Actions
action field that identifies the stage, and a resource field with the Cart ID. AI Hub constructs this payload automatically based on the checkout event.The following example shows the structure of a request body:
{
"action": "Create",
"resource": {
"typeId": "cart",
"id": "<cart-id>"
}
}
Action types
| Action | Description |
|---|---|
Create | Checkout session initialized |
Update | Cart or session updated |
Read | Current checkout state retrieved |
Complete | Checkout completion requested |
Create
Invoked when a checkout session is initialized. Use this action to set up context for the checkout flow.
Typical integrations:
- checkout context setup
- external system initialization
Update
Invoked when the Cart or session is updated. Use this action to revalidate Cart changes or sync with external systems.
Typical integrations:
- inventory validation (soft check)
- external system synchronization
Read
Invoked when an agent retrieves the current state of the checkout. Use this action to return the latest validation state without modifying the Cart.
Typical integrations:
- checkout state synchronization
Complete
Invoked as the final validation step before Order creation. Use this action for hard checks that determine whether checkout can proceed.
Typical integrations:
- fraud detection
- inventory validation (hard check)
- business rule enforcement
Request format
This section describes the exact format of the HTTP request that AI Hub sends to your endpoint. Use this as a reference when building your service.
Headers
| Header | Description |
|---|---|
Authorization | Configured Extension secret, sent as-is |
Content-Type | application/json |
Body
action identifier and a Cart reference. No additional Cart data, customer information, or channel details are included in the payload.id.Response format
Your endpoint must return a JSON response that tells AI Hub the outcome of the validation. The response can include a result type and validation errors.
Structure
{
"result": {
"type": "Success",
"errors": []
}
}
Result object
| Field | Type | Required | Description |
|---|---|---|---|
type | String | Yes | Success or Failure. Indicates whether the checkout can proceed. |
errors | Array | Conditional | Validation errors that block checkout. Required when type is Failure. |
Success response
Success response indicates that checkout can proceed:{
"result": {
"type": "Success"
}
}
Failure response
Failure response blocks checkout. At least one error must be included:{
"result": {
"type": "Failure",
"errors": [
{
"code": "VALIDATION_ERROR",
"message": "Checkout failed"
}
]
}
}
Failure response, the Cart is preserved. The shopper (or agent) receives the error messages from the response and can adjust the Cart — for example, by changing quantities or updating the shipping address. Each adjustment triggers a new webhook request, allowing re-validation until checkout succeeds.Errors
Structure
{
"code": "VALIDATION_ERROR",
"message": "Item is out of stock"
}
| Field | Type | Description |
|---|---|---|
code | String | Error code identifying the type of error. |
message | String | Human-readable description of the error. |
Failure response blocks checkout. You can return multiple errors in a single response. Only hard errors are supported — warnings are not currently available. Errors should be consistent and deterministic to ensure predictable checkout behavior.HTTP status codes
| Status | Description |
|---|---|
200 | Request processed. Business logic outcome is in the response body. |
4xx | Client error. |
5xx | Server error. |
"type": "Failure", not through HTTP status codes.Timeouts
The default timeout is 10 seconds (10000 ms). You can override this value in the Merchant Center configuration.
5xx, or cannot be completed because of a network error, AI Hub ignores the webhook result and proceeds with checkout. This is a fail-open behavior that prioritizes checkout completion over blocking the shopper due to a technical issue with the webhook endpoint.In these technical failure cases, no webhook-provided changes are applied to the Cart/session. The Cart/session remains in the state it was in before the webhook call, and checkout continues without any validation results or other enrichments that would have come from that webhook response.
Idempotency and retries
200 response. A timeout, HTTP 5xx, or network error does not roll back the shopper's checkout session; instead, the webhook result is discarded and the Cart/session remains unchanged by that webhook attempt.Because failed webhook attempts do not apply partial webhook-driven changes, a later retry is effectively a fresh attempt against the current Cart/session state. AI Hub does not implement idempotency headers or automatic retries on its end.
200 response with "type": "Failure" is a deliberate business decision and still blocks checkout, as described in Failure response.