API reference
Ask
Answer a shopper’s question using your catalogue, prices, stock levels, shipping rates and content.
On this page
The Ottla ask API accepts a question and returns a short answer, along with products that can be viewed or added to the basket. If we don’t have the information to answer the question, we say so plainly and can offer to pass the shopper to a team member rather than guess. If a query is vague (“a tent for the Lakes”), we may ask one short clarifying question with 2 to 4 options for the shopper to tap. It’s like having an ecommerce question answering API that only answers from what you’ve given it.
Prices and stock are taken from your store’s own data, synced via our Magento module or sent using the ingestion endpoints. Any mention of price or stock that we cannot back up with that data is removed by guardrails. Delivery options and costs are pulled from your store’s shipping rates, and the assistant does not promise a delivery date that your store has not given.
Each answer uses one answered question from your monthly allowance, polite refusals included. Comparing products with /compare doesn’t use any.
Ask a question
Answers one shopper question. Send the page the shopper is on, and the same session_id for every question in a conversation, so follow-ups such as “and in green?” make sense. Call it from your server, sending one of the key’s allowed origins as Origin; the ask rate limit group is shared with /compare and /search.
- Key
Authorization: Bearerwith theask:readscope- Origin
- One of the key’s allowed origins
- Call from
- The browser or your server
- Rate limit
askgroup, set by your plan- Retries
- Safe with
Idempotency-Key
Headers and parameters
| Field | Description |
|---|---|
Origin
|
Your storefront’s address, which must be one of the key’s allowed origins. Browsers send it themselves; a server must send it too. |
Idempotency-Key
|
Makes a retry safe: the same key, path and body within 24 hours returns the first response again. A key is shared by every API key and store in the workspace, so it must be unique to each request (a random id, not a row number from one store’s database): reusing the key with a different body is refused with 409. Servers only. |
X-Ottla-Client-Ip
|
The shopper’s public IP address, when your server calls on a shopper’s behalf, so each shopper has their own allowance. Read only for a key marked “Used by a store connector or another server” in the console, which also needs allowed IP addresses; ignored for any other key. |
X-Ottla-Request-Id
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
200 OK
The answer, or
human_activewhile a person is handling the chat. -
401 Unauthorised
No API key was sent (
unauthenticated), or the key is unknown, revoked or expired (invalid_api_key). -
402 Payment required
Billing needs attention.
plan_limit_exceeded: the plan’s allowance and any credits are used up (the body addsmetric,usedandlimit).account_past_due: a payment is overdue, or a trial ended without a plan.account_suspended: the account is suspended. Stop sending until the workspace owner resolves it atupgrade_url. -
403 Forbidden
As for any storefront operation (see the
ForbiddenStorefrontresponse), andip_not_allowedwithstatus: "hidden"when thewidgetsent is limited to other networks: hide the chat for this shopper.Error codes:
forbidden_scopetenant_suspendedorigin_not_configuredorigin_requiredorigin_invalidorigin_not_allowed -
409 Conflict
The
Idempotency-Keywas used before with a different body (idempotency_key_reused), or a request with it is still running (idempotency_in_flight). -
422 Invalid
The request is not valid (
validation_failed, witherrorskeyed by field), or theIdempotency-Keyheader is malformed (invalid_idempotency_key). -
429 Rate limited
A rate limit was reached: this key’s limit for the operation’s group (
rate_limited), the workspace’s limit across all its keys (tenant_rate_limited), the limit for one network address (ip_rate_limited) or for one shopper (shopper_rate_limited). Waitretry_afterseconds. -
503 Unavailable
This capability is temporarily paused by Ottla (
feature_disabled). Try again afterRetry-Afterseconds;help_urlshows the service status.
Request fields
| Field | Description |
|---|---|
question
|
The shopper’s question, up to 2,000 characters. |
session_id
|
Your id for the conversation, up to 128 characters. Reuse it for every question in the chat, and send it with feedback, handoffs and conversation reads. |
vid
|
A stable id for the shopper’s browser, up to 128 characters. Send it only with the shopper’s consent. It lets the shopper reopen their earlier chats. |
website_id
|
Ottla’s id for the website. Ignored for a key bound to one website, as every storefront key is. |
scope_ref
|
Your code for the market or language the shopper is browsing, up to 64 characters, such as uk. Leave it out to use the website’s default. |
locale
|
The shopper’s language, up to 35 characters, such as en-GB. |
currency
|
The currency to show prices in, up to 8 characters, such as GBP. |
store_view_id
|
The store view, for a catalogue organised by store view. An older alternative to scope_ref. |
widget
|
Your widget’s public id, up to 64 characters. Applies that widget’s IP allow-list, so a shopper outside it gets 403 ip_not_allowed. |
| Field | Description |
|---|---|
sku
|
The SKU of the product the shopper is looking at, up to 255 characters. |
page_type
|
The kind of page: home, cms, plp (a listing), search, pdp (a product page), cart (the basket page), checkout, success (order confirmation), account or other. |
placement
|
Where the chat sits on the page: chat, sidebar or inline. |
surface
|
The location on the page that the chat dialog was invoked from, up to 100 characters, such as pdp_questions. An order following a question asked via this can also appear against this feature in Analytics. |
page_context
|
The product on the page with its current details: product.sku, product.name, product.url and product.attributes (up to 50 attributes). |
basket
|
The shopper’s basket, so the assistant can answer questions about it: items (sku, name, qty and the line price as shown), subtotal and grand_total. |
context
|
Further facts about the page as key and value pairs, up to 50 keys. |
channel_secret
|
Only while a live chat is open: the secret from POST /escalation, so the shopper’s message reaches the person handling the chat. |
We ignore any fields that attempt to set a customer group or shopper identity, meaning you receive guest prices when making a direct call. Customer group prices can only reach Ottla via our Magento module, as the module can vouch for who a signed-in shopper is.
Example request
curl https://ottla.ai/api/v1/ask \
-H "Authorization: Bearer YOUR_BROWSER_KEY" \
-H "Origin: https://shop.example" \
-H "Content-Type: application/json" \
-d '{"question": "Will the Ridgeline 2 fit in a 40 litre rucksack?", "session_id": "sess_8f2c1", "sku": "TENT-2P", "page_type": "pdp", "placement": "chat"}'
// On your server (Node 18 or later)
import { randomUUID } from 'node:crypto';
const res = await fetch('https://ottla.ai/api/v1/ask', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_BROWSER_KEY',
'Content-Type': 'application/json',
'Origin': 'https://shop.example', // one of the key's allowed origins
'Idempotency-Key': randomUUID(),
},
body: JSON.stringify({
question: 'Will the Ridgeline 2 fit in a 40 litre rucksack?',
session_id: 'sess_8f2c1',
sku: 'TENT-2P',
page_type: 'pdp',
placement: 'chat',
}),
});
const answer = await res.json();
<?php
use GuzzleHttp\Client;
$client = new Client(['base_uri' => 'https://ottla.ai/api/v1/']);
$response = $client->post('ask', [
'headers' => [
'Authorization' => 'Bearer YOUR_BROWSER_KEY',
'Origin' => 'https://shop.example',
'Idempotency-Key' => bin2hex(random_bytes(16)),
],
'json' => [
'question' => 'Will the Ridgeline 2 fit in a 40 litre rucksack?',
'session_id' => 'sess_8f2c1',
'sku' => 'TENT-2P',
'page_type' => 'pdp',
'placement' => 'chat',
],
]);
$answer = json_decode((string) $response->getBody(), true);
Response
{
"answer_id": 58213,
"answer": "Yes. The Ridgeline 2 packs down to 45 x 15 cm and weighs 2.1 kg, so it fits in most 40 litre rucksacks.",
"blocks": [
{
"type": "text",
"version": "1.0",
"content": "Yes. The Ridgeline 2 packs down to 45 x 15 cm and weighs 2.1 kg, so it fits in most 40 litre rucksacks."
},
{
"type": "product_cards",
"version": "1.0",
"items": [
{
"sku": "TENT-2P",
"name": "Ridgeline 2 Person Tent",
"url": "https://shop.example/ridgeline-2-person-tent",
"image_url": "https://shop.example/media/tent-2p.jpg",
"price": "£129.00"
}
]
},
{
"type": "quick_replies",
"version": "1.0",
"items": [
{ "label": "How long does it take to pitch?", "value": "How long does it take to pitch?" }
]
}
],
"confidence": "high",
"suggested_follow_ups": ["How long does it take to pitch?"],
"recommended_products": [
{
"sku": "TENT-2P",
"name": "Ridgeline 2 Person Tent",
"url": "https://shop.example/ridgeline-2-person-tent",
"image_url": "https://shop.example/media/tent-2p.jpg",
"price": "£129.00"
}
],
"fallback": false,
"refusal_reason": null,
"sources": []
}
| Field | Type | What it holds |
|---|---|---|
| answer_id | integer | The answer’s id. Send it with feedback and events about this answer. |
| answer | string | The answer as plain text. It always carries the whole answer, so it works on its own. |
| blocks | array | What to show, in order. See Answer blocks below. |
| confidence | string | high, medium or low: how well your catalogue and content covered the question. |
| suggested_follow_ups | array | Short questions the shopper might ask next. |
| recommended_products | array | Up to 6 products the answer recommends: sku, name, url, image_url and price with its currency symbol. |
| fallback | boolean | true when the assistant couldn’t answer and answer holds your fallback message. |
| refusal_reason | string or null | Why the assistant didn’t answer. See Refusal reasons below. |
| sources | array | Always empty, kept for later. Each answer in the Questions log shows the sources it used. |
Answer blocks
Each block in blocks has a type and a version (currently "1.0"), following the ottla.blocks.v1 set. Blocks add to the written answer rather than replace it, so render the types you support, in order, and skip the rest. A front end that shows only text and product_cards still gives shoppers the full answer. New types may be added at any time.
| Type | What it shows |
|---|---|
text | The answer in words, in content. Always present. |
product_cards | Products as cards, in items, each with a link, image and price. |
comparison_table | Two or more products side by side, attribute by attribute. |
quick_replies | Replies to tap, in items (label and value). Send the value back as the next question. |
clarification | One short clarifying question with 2 to 4 options, when the request was vague. |
cart_summary | What’s in the shopper’s basket, when they ask about it. |
order_status | Where a signed-in shopper’s order has got to. Needs order data from the Magento module. |
shipping_estimate | Delivery options and costs from your store’s shipping rates. |
reviews | What reviewers say about a product. |
promotion | A current offer that applies to the products in the answer. |
no_results | Nothing in your catalogue matched, with a way forward. |
error | The assistant couldn’t answer just now. With retry: true it’s safe to ask again. |
availability | Stock for a product or its options. |
account_summary | Details from a signed-in shopper’s account. Needs the Magento module. |
faq | A question and answer from your FAQs that matches. |
bundle | Products that go together, such as everything needed for a job. |
add_to_cart_confirm | Confirms a product went into the basket. |
human_handoff | An offer to talk to a person on your team. Sent only to clients that advertise the handoff capability, as Ottla’s own widget does. |
Refusal reasons
When the assistant doesn’t answer, fallback is true and refusal_reason says why, so your code can react: offer a person, show a search box or simply display the message. Most reasons point at something missing from your data, which is good news, because you can fix it. Every refusal also appears in AI assistant → Questions log with what to add, and repeated ones are grouped in Catalogue gaps.
| Value | What happened | What to add or check |
|---|---|---|
out_of_scope | The question isn’t about your store or its products. | Nothing. This is the assistant staying on topic. |
pricing_not_authored | Your data has no price information that answers it. | Check the product’s prices are syncing, or add your pricing policy as a page. |
stock_not_known | Stock for the product isn’t known. | Send stock with the product, or check stock is syncing. |
delivery_not_authored | Your data doesn’t cover delivery for this question. | Add a delivery information page or your shipping rates. |
warranty_not_authored | There’s no warranty information to answer from. | Add your warranty policy or the product’s warranty terms. |
compatibility_not_authored | Nothing says whether these products work together. | Add compatibility details to the product’s attributes or a spec sheet. |
safety_guardrail | The answer would have made a safety claim your content doesn’t support. | Add the manual, installation guide or spec sheet that states it. |
prompt_injection | The message tried to change how the assistant behaves. | Nothing. The instruction was ignored. |
no_sources | Nothing in your catalogue or content answers it. | Add the missing product details, FAQ or page. |
low_confidence | What matched wasn’t enough to answer well. | Fill out the product’s description and attributes. |
not_authored | A claim was removed because your data doesn’t support it. | Add the fact to your product data or content. |
other | Any other reason. | Open the question in the Questions log for detail. |
New values may be added. Treat any value you don’t recognise as a refusal and show the message in answer.
Other successful responses
Three 200 responses aren’t ordinary answers. Handle them and your chat will never look stuck.
| Response | What it means | What to do |
|---|---|---|
status is human_active, with escalation_id and message | A person from your team is handling this session’s live chat. | Show the message, and send the shopper’s next messages to POST /escalation/message. |
fallback is true, the last block is an error block with retry: true, and refusal_reason is null | The assistant couldn’t answer just now. | It’s safe to ask again, ideally after a short pause. |
A clarification or quick_replies block with 2 to 4 options | The request was vague and the assistant asked one short question. | Show the options. Send the one the shopper taps as the next question, with the same session_id. |
Errors
| Status | Code | What to do |
|---|---|---|
| 401 | unauthenticated, invalid_api_key | Send a valid key. A revoked or expired key needs replacing. |
| 402 | plan_limit_exceeded | The monthly answered questions and credits are used up. The body adds metric, used, limit and upgrade_url. Hide the chat until credits are added, the plan changes or the month resets. |
| 402 | account_past_due, account_suspended | Billing needs attention. Hide the chat until the workspace owner resolves it at upgrade_url. |
| 403 | forbidden_scope | The key doesn’t have ask:read. |
| 403 | origin_not_configured, origin_required, origin_invalid, origin_not_allowed | The Origin check failed. See API keys and allowed origins. |
| 403 | ip_not_allowed | The key, or the widget you named, is limited to other networks. When the body has status: "hidden", hide the chat for this shopper. |
| 409 | idempotency_key_reused, idempotency_in_flight | See Idempotency. |
| 422 | validation_failed, invalid_idempotency_key | Fix the fields listed in errors. |
| 429 | rate_limited and the other limit codes | Wait retry_after seconds. See Rate limits. |
| 503 | feature_disabled | Ottla has paused this capability for a short time. Try again after Retry-After seconds. |
Compare products
Returns two to five products side by side, attribute by attribute, for your own comparison table. There’s no written answer, so no answered question is used. Same scope, Origin check and rate limit group as /ask.
- Key
Authorization: Bearerwith theask:readscope- Origin
- One of the key’s allowed origins
- Call from
- The browser or your server
- Rate limit
askgroup, set by your plan- Retries
- Safe with
Idempotency-Key
Headers and parameters
| Field | Description |
|---|---|
Origin
|
Your storefront’s address, which must be one of the key’s allowed origins. Browsers send it themselves; a server must send it too. |
Idempotency-Key
|
Makes a retry safe: the same key, path and body within 24 hours returns the first response again. A key is shared by every API key and store in the workspace, so it must be unique to each request (a random id, not a row number from one store’s database): reusing the key with a different body is refused with 409. Servers only. |
X-Ottla-Client-Ip
|
The shopper’s public IP address, when your server calls on a shopper’s behalf, so each shopper has their own allowance. Read only for a key marked “Used by a store connector or another server” in the console, which also needs allowed IP addresses; ignored for any other key. |
X-Ottla-Request-Id
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
200 OK
The products and the comparison.
-
401 Unauthorised
No API key was sent (
unauthenticated), or the key is unknown, revoked or expired (invalid_api_key). -
402 Payment required
Billing needs attention.
plan_limit_exceeded: the plan’s allowance and any credits are used up (the body addsmetric,usedandlimit).account_past_due: a payment is overdue, or a trial ended without a plan.account_suspended: the account is suspended. Stop sending until the workspace owner resolves it atupgrade_url. -
403 Forbidden
The key cannot be used for this request:
forbidden_scope,ip_not_allowedortenant_suspendedas for any key, or theOrigincheck failed:origin_not_configured,origin_required,origin_invalidororigin_not_allowed. -
409 Conflict
The
Idempotency-Keywas used before with a different body (idempotency_key_reused), or a request with it is still running (idempotency_in_flight). -
422 Invalid
The request is not valid (
validation_failed, witherrorskeyed by field), or theIdempotency-Keyheader is malformed (invalid_idempotency_key). -
429 Rate limited
A rate limit was reached: this key’s limit for the operation’s group (
rate_limited), the workspace’s limit across all its keys (tenant_rate_limited), the limit for one network address (ip_rate_limited) or for one shopper (shopper_rate_limited). Waitretry_afterseconds. -
503 Unavailable
This capability is temporarily paused by Ottla (
feature_disabled). Try again afterRetry-Afterseconds;help_urlshows the service status.
| Field | Description |
|---|---|
skus
|
The products to compare: 2 to 5 SKUs. |
website_id
|
Ottla’s id for the website. Ignored for a key bound to one website. |
curl https://ottla.ai/api/v1/compare \
-H "Authorization: Bearer YOUR_BROWSER_KEY" \
-H "Origin: https://shop.example" \
-H "Content-Type: application/json" \
-d '{"skus": ["TENT-2P", "TENT-3P"]}'
<?php
use GuzzleHttp\Client;
$client = new Client(['base_uri' => 'https://ottla.ai/api/v1/']);
$response = $client->post('compare', [
'headers' => [
'Authorization' => 'Bearer YOUR_BROWSER_KEY',
'Origin' => 'https://shop.example',
],
'json' => ['skus' => ['TENT-2P', 'TENT-3P']],
]);
$comparison = json_decode((string) $response->getBody(), true);
{
"products": [
{ "id": 4101, "sku": "TENT-2P", "name": "Ridgeline 2 Person Tent", "url": "https://shop.example/ridgeline-2-person-tent", "image_url": "https://shop.example/media/tent-2p.jpg", "attrs_json": { "berths": 2, "weight_kg": 2.1 } },
{ "id": 4102, "sku": "TENT-3P", "name": "Ridgeline 3 Person Tent", "url": "https://shop.example/ridgeline-3-person-tent", "image_url": "https://shop.example/media/tent-3p.jpg", "attrs_json": { "berths": 3, "weight_kg": 2.9 } }
],
"comparison_matrix": [
{ "attribute": "berths", "TENT-2P": 2, "TENT-3P": 3 },
{ "attribute": "weight_kg", "TENT-2P": 2.1, "TENT-3P": 2.9 }
]
}
products holds each product’s id, SKU, name, link, image and attributes in attrs_json. comparison_matrix has one row per attribute: attribute, then one key per SKU with that product’s value, or null when it has none. Prices are left out on purpose, because they change more often than attributes: show them from a product card. Hidden and disabled products are never compared. In Ottla’s own chat, shoppers can compare up to 4 products at once.
How the widget shows an answer
If you decide to build your own chat, this is the shape you should be aiming for: the text answer first, then cards and then quick replies.
FAQ
Questions developers ask
Does every call use an answered question?
Every answer from /ask does, polite refusals included. /compare doesn’t, and nor do search, recommendations or starter questions.
Why is sources always empty?
It’s reserved for future use and always returns an empty array. Your team can see what sources were used to answer each question under AI assistant → Questions log. Shoppers do not see these.
What should I do with block types I don’t support?
Skip them. Every block adds to the written answer, so answer and the text block stand on their own.
Can the assistant quote trade prices through the API?
No. You receive guest prices when making a direct API call. Customer group prices can only be sent via our Magento module, which can vouch for a signed-in shopper.
What happens when the monthly allowance runs out?
/ask answers 402 plan_limit_exceeded until credits are added, the plan changes or the month resets. While the assistant is paused, storefront reads such as search and recommendations return empty results rather than errors, as When the assistant is paused explains.
Related
Feedback
Add a thumbs up or down to an answer, using its answer_id.
Events and revenue attribution
Report when a shopper clicks a card from an answer and any subsequent orders.
Escalations
Pass a chat to your team when the assistant can’t help.
Errors
All error codes that can be returned from the API and what to do.
Check out our AI shopping assistant feature page to learn what shoppers experience and how you can configure it for your store.