Tanqory AI for apps
Run Tanqory AI generators from your app's server, paid from the store's AI credits up to the limit the merchant sets.
Your app can ask Tanqory AI for content, such as a summary of a product's reviews. The store pays with its own AI credits, up to a limit the merchant controls for your app. You never hold a model key and never pay for the model.
Ask for the scope
Add write_ai_generations to your app's scopes in Configuration, then select Save version. It lets your app run the generators open to apps, and nothing else: no chat, no store data. Ask for the read scope a generator names too (review_summary needs read_products).
The merchant sees the scope on the install page, with the most AI credits your app may use each credit period (100 by default). Only an owner, or a staff member allowed to manage AI spend, can grant it.
Call it from your server only
Send tanqoryExtAiGenerate to the Admin API with your app's access token, from your own server. Never call it from a browser or put the token in a page.
mutation {
tanqoryExtAiGenerate(
generator: "review_summary"
idempotencyKey: "reviews-8f2c41a0-v12"
input: {
productTitle: "Linen shirt"
language: "en"
reviews: [
{ rating: 5, title: "Great fit", body: "Soft linen, true to size." }
{ rating: 2, body: "Shrank after a warm wash." }
]
}
) {
result { output credits replayed }
userErrors { code message field }
}
}An offline token works for the store. An online token, acting for a staff member, works only when that member may use AI and make changes in the store.
Run one tanqoryExtAiGenerate per request. tanqoryExtAiGenerators lists the generators your app may run, with their input and output schemas.
Derive the key from the content
idempotencyKey names the request: 8 to 128 letters, digits, _ or -. Build it from what you send, such as the product id and a version of its reviews (reviews-<productId>-v12), not from the time or a random value.
- The same key with the same input returns the stored result at no cost (
replayed: true). - The same key with a different input is refused with the error code
idempotency_key_reused. You never get another request's result. Use a new key. - A result is kept for 30 days. A replay after that answers the error code
replay_unavailable: send it again with a new key.
The review_summary generator
Input:
| Field | Type | Limit |
|---|---|---|
productTitle | string, optional | 255 characters |
reviews | list of { rating, title, body } | 1 to 200 reviews; rating 1 to 5; title optional, 200 characters; body 4,000 characters; 60,000 characters of titles and text in all |
language | string, optional | a BCP 47 tag, such as en or th |
Send no customer names, emails or other personal details: the input has no field for them, so leave them out of the review text too. What you send goes to Tanqory's AI provider to write the result.
Output:
| Field | Type | Limit |
|---|---|---|
summary | plain text | 600 characters |
pros | list of short phrases | 5 |
cons | list of short phrases | 5 |
The output never holds a web address, an email address, a phone number, HTML or Markdown: an answer that does is withheld with REFUSED. Still escape the text when you show it, and label it as AI-generated on the storefront.
What each error means
| Code | Why | What to do |
|---|---|---|
ACCESS_DENIED | The token lacks write_ai_generations or the generator's scope; the generator is not open to apps; the merchant or Tanqory turned AI off for your app | Ask for the scope; tell the merchant they can turn AI on in Settings > Apps |
SPEND_LIMIT_REACHED | Your app reached its limit for the credit period, or the store reached its own limit | Tell the merchant: an owner or admin can raise your app's limit in Settings > Apps. It starts again next period |
INSUFFICIENT_CREDITS | The store has no AI credits left | Tell the merchant they can buy credits on Settings > Billing > AI usage |
THROTTLED | Too many requests from your app in this store in the last minute, three already running, or the day's requests on a partner's development stores are used up | Wait and retry with the same key |
INVALID | The input breaks the schema | Fix the field named in field |
REFUSED | The answer did not pass Tanqory's output checks | Retry later with a new key |
UNAVAILABLE | Tanqory AI is paused or not reachable | Retry later with the same key |
Nothing is charged for a request refused before the model runs. A refused answer (REFUSED) used the model and is charged.
Development stores
On your development stores the same rules and real billing apply, from the store's trial credits. All your development stores together share a daily number of AI requests.