Skip to content
Ainvented
PlatformObservabilityFor partnersPricingCustom softwareFAQDocs
Sign inBuild an agent
Platform/Observability/For partners/Pricing/Custom software/FAQ/Documentation
Sign inBuild an agent

API reference

Explore the platform
v1

Start here

Quickstart
Introduction
Authentication
Admin vs project-scoped
Rate Limits
Tracing & Observability

Build and run

Chat CompletionsPOST
Model tiersStreamingStreaming reasoningStructured outputSession ManagementProject SelectionSkills & GuardrailsWorkflow in ChatTools Override
Tasks
EndpointsTriggersScope (project vs. global)Selecting tasksInline function toolsResult-delivery modesReading results & deliveryhistory_scope & limitsCost & quotasError codes
Multimodal Content
Content TypesImage ExamplesAudio ExamplesBrowser UploadCombined ExampleImage generationImage responsesValidation & ErrorsToken Estimation
Voice
OverviewLanguages and voicesCost & meteringCreate speechTranscribeList voicesRead a voiceHear a voiceDesign a voiceClone a voiceRename a voiceDelete a voiceCreate a voice projectList voice projectsRead a voice projectUpdate a voice projectArchive a voice projectHistoryRead a history entryRemove a history entryDownload audio
Decisions
OverviewQuestion typesActing on the answersCost & meteringMake a decisionCreate a decision projectList decision projectsRead a decision projectUpdate a decision projectArchive a decision projectHistoryRead a runRemove a run
Execute WorkflowPOST
Input ParametersOutput FormatError Responses

Manage

Projects
CreateListBulk cache lifetimeBulk model and effortReadUpdateProject balanceDelete
Guardrails & Skills
OverviewUse them in a chat requestChat with guardrails and skillsCreate a guardrailList guardrailsRead a guardrailUpdate a guardrailDelete a guardrailCreate a skillList skillsRead a skillUpdate a skillDelete a skillAcross projectsList across projectsAdd or update by nameSwitch on or off by nameRemove by name
PaymentsPOST
Create a paymentList paymentsRead a paymentSave a cardList saved cardsAuto-reloadWebhook events
WhatsAppPOST
Assistant vs API modeCreate a connect linkCheck connect linksList accountsRead an accountUpdate an accountWho wrote inRead messagesSend a messageDownload mediaList templatesCreate a templateUpload a header sampleRead a templateEdit a templateDelete a templateRegister a webhookManage webhooksTraffic of a projectEvery number, all projectsBulk mode / activeTraffic, all projectsWebhook on every projectWebhook payload & signatureWhat your customer sees
MessengerPOST
Assistant vs API modeThe messaging windowsCommentsCreate a connect linkCheck connect linksList accountsRead an accountUpdate an accountDisconnect an accountWho wrote inRead a conversationPause or resume the assistantRead messagesSend a messageRead a messageDownload a fileRead commentsRead a commentReply to a commentRegister a Messenger webhookList webhooksRead a webhookUpdate a webhookDeactivate a webhookTest a webhookTraffic of a projectEvery account, all projectsBulk mode / active / commentsTraffic, all projectsWebhook on every projectWebhook payload & signatureWhat your customer sees
InstagramPOST
Assistant vs API modeThe messaging windowsCommentsCreate a connect linkCheck connect linksList accountsRead an accountUpdate an accountDisconnect an accountWho wrote inRead a conversationPause or resume the assistantRead messagesSend a messageRead a messageDownload a fileRead commentsRead a commentReply to a commentRegister an Instagram webhookList webhooksRead a webhookUpdate a webhookDeactivate a webhookTest a webhookTraffic of a projectEvery account, all projectsBulk mode / active / commentsTraffic, all projectsWebhook on every projectWebhook payload & signatureWhat your customer sees
Project API keys
CreateListRevoke
Consumption
Read consumption
Promotions
Resolve a promo codeRedeem a promo codeReferral stats
Vector Stores
OverviewNode.js clientCreate / list / getAdd / list documentsDocument metadataSupported file typesQuery (search + RAG)Metadata filtersDeleteCost & metering

Reference

Webhooks
RegisterListUpdate / rotate secretDeleteTest firePayload & signature
Error Codes
Best Practices
Additional Resources
Developer platformREST API · v1

API Documentation

Build, deploy, and observe Ainvented agents with a clear REST API. Start with one request, then add sessions, tools, files, tasks, and production controls as you need them.

Start the quickstart→Open the full reference
01AuthenticateChoose the right key scope02Send a requestChat, stream, or run tools03Observe the runTrace latency, usage, and cost
Two-minute quickstart

Send your first message

Create an API key, keep it on your server, and make one chat-completion request.

  1. 1
    Create a key

    Open API Key Management and copy your key once. Never expose it in browser code.

  2. 2
    Call the API from your server
    Terminal
    export API_KEY="your_api_key_here"
    
    curl https://ainvented.com/api/v1/chat/completions \
      -H "Authorization: Bearer $API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "ainvented-lite",
        "messages": [{"role": "user", "content": "Hello from Ainvented"}]
      }'

    Already use a chat-completions SDK? Set its base URL to https://ainvented.com/api/v1 and its API key to your key — nothing else changes: developer messages, max_completion_tokens, streamed usage and function calling work as you write them today.

  3. 3
    Read the answer

    The generated text is in choices[0].message.content, and model names the model that answered. Save the returned session_id when you want Ainvented to maintain conversation history. To use another model, change model — see model tiers.

Start here

Introduction

The Ainvented REST API gives your applications programmatic access to agents and their projects through a consistent interface. Use familiar HTTP patterns while Ainvented manages model access, sessions, tools, context, and observability.

API origin
https://ainvented.com
Authentication
A Bearer API key, sent from your server. Two key scopes.
Format
JSON in, JSON out. Streaming answers arrive as server-sent events.
Errors
One envelope for every failure. Error codes.
Where things are
  • Chat CompletionsGenerate text, stream it, keep sessions, pick a tier, run tools.
  • TasksReusable jobs that read a conversation and return structured data.
  • Multimodal ContentImages and audio in messages, generated images in responses.
  • Voice18 callsNatural speech, voices designed or cloned, and transcripts — on their own or in voice projects.
  • Decisions9 callsYes/no, choice and score answers about any text or JSON, with probabilities — alone or in decision projects.
  • Execute WorkflowRun a workflow project with inputs and read its output by node.
  • Projects8 callsCreate projects, set budgets and quotas, pick defaults.
  • Guardrails & Skills15 callsStanding rules and instructions every chat turn follows — stored on a project, or sent with one request.
  • Payments6 callsCharge your end-clients and top up balances or project budgets.
  • WhatsApp22 callsConnect a customer’s WhatsApp number to a project; reply with the assistant or from your app; manage templates; read traffic everywhere.
  • Messenger27 callsConnect a customer’s Facebook Page; the assistant or your app answers messages and comments; a person can reply for 7 days.
  • Instagram27 callsConnect a customer’s Instagram professional account, no Facebook Page needed; messages, comments and replies as on Messenger.
  • Project API keys3 callsMint, list and revoke keys that are bound to one project.
  • Consumption1 callTokens and cost per project, broken down by what consumed them.
  • Promotions3 callsPromo codes and referral links.
  • Vector Stores4 callsStore documents, search them semantically, optionally get a generated answer.
  • Webhooks5 callsSigned HTTPS notifications for budget, token and usage events.
  • Error CodesThe one error envelope and every status you can get back.
  • Best PracticesKeys, retries, sessions, streaming, timeouts.
  • Additional ResourcesWhere to go next.
Start here

Authentication

Ainvented v1 API requests use Bearer tokens unless an endpoint is explicitly marked public or browser-session only. Include your API key in the Authorization header:

HTTP header
Authorization: Bearer YOUR_API_KEY

Security note

Keep your API keys secure and never expose them in client-side code. API keys provide full access to your chat projects.

Admin keys vs project-scoped keys

Every API key has one of two scopes. The scope is fixed at creation time and determines what the key can do.

Admin
Account-wide management key. Required for every endpoint under /v1/projects — listing, reading, updating, deleting, minting per-project keys, configuring webhooks, viewing consumption, and the partner payment surface (payments, payment methods, auto-recharge).
Project-scoped
Bound to one project. Can use only the runtime endpoints — /v1/chat/completions, /v1/tasks, /v1/vector-stores, /v1/workflows — which silently resolve to the bound project. Cannot read or modify anything under /v1/projects(no list, read, update, delete, key management, webhooks, consumption, or billing). Intended for partner-enabled accounts to give their clients a key that uses the product without exposing the project-management surface.
Error code for the management surface

Every call to a /v1/projects endpoint (list, detail, nested api-keys / consumption / webhooks, and the partner billing routes) with a project-scoped key returns:

  • admin_key_required — 403 permission_error. Use an Admin key to manage projects.
  • key_project_mismatch — 403 permission_error. Returned by vector-store store-targeted endpoints (/v1/vector-stores/{id}/...) when a project-scoped key targets a store that lives in a different project.
Start here

Rate Limits

API requests are rate limited using a token bucket algorithm. Rate limit information is included in response headers:

  • X-RateLimit-Limit: Maximum requests per time window
  • X-RateLimit-Remaining: Requests remaining in current window
  • X-RateLimit-Reset: Unix timestamp when limit resets

When rate limited, the API returns a 429 Too Many Requests response with a Retry-After header indicating seconds until reset.

Start here

Request Tracing & Observability

Every response from POST /v1/chat/completions — success or error, streaming or non-streaming — includes an X-Request-Id header (UUID). This id correlates the request with its usage events and, when the project is attached to an Observability project, with its captured trace. The header is purely additive — request and response bodies are unchanged. Every charge of the request is booked under it — a generated picture and the text of the same turn included — and the billed answers of the other APIs carry it too: decisions, speech, transcriptions, and a vector store's document upload and query (a query with answer books its search and its answer under the one id); a task run's request_id is the id of its charges.

  • Attach a chat project to an Observability project (sidebar → Observability) to see per-request traces: prompt, completion, model, tokens, cost, latency, TTFT and status.
  • Trace capture runs after the response is sent and never adds latency to your requests.
  • LLM-as-a-judge evaluations run against your project budget and appear in the project's consumption ledger like any other usage.
GET/api/v1/models#

List Models

List the model tiers this account can use. Uses the standard list-models shape, so a compatible client library or model picker populates itself with no Ainvented-specific code.

Authentication

Bearer token required in Authorization header

Response Schema

JSON type shapeExpand
{
  "object": "string",
  "data": [
    {
      "id": "string",
      "object": "string",
      "created": "number",
      "owned_by": "string"
    }
  ]
}
Fields6Expand
object
string
'list'
data
array
array — fields below
id
string
The model tier name to pass as `model` on /v1/chat/completions, most capable first: 'ainvented-eon' (our most capable model, where it is offered), 'ainvented-epic', 'ainvented-saga', 'ainvented-lite' and 'ainvented-low'.
object
string
'model'
created
number
Unix timestamp of when the tier became available. Stable; it does not change between calls.
owned_by
string
'ainvented'

Code Examples

Every tier you may pass as `model`

curl https://ainvented.com/api/v1/models \
  -H "Authorization: Bearer $API_KEY"

# {
#   "object": "list",
#   "data": [
#     { "id": "ainvented-eon",     "object": "model", "created": 1792368000, "owned_by": "ainvented" },
#     { "id": "ainvented-epic",    "object": "model", "created": 1783036800, "owned_by": "ainvented" },
#     { "id": "ainvented-saga",    "object": "model", "created": 1783036800, "owned_by": "ainvented" },
#     { "id": "ainvented-lite",    "object": "model", "created": 1735689600, "owned_by": "ainvented" },
#     { "id": "ainvented-low",     "object": "model", "created": 1751328000, "owned_by": "ainvented" }
#   ]
# }
# Most capable first. Our most capable model, ainvented-eon, heads the list where it is offered.

Returns a single model object, or 404 if the tier is not available to you

curl https://ainvented.com/api/v1/models/ainvented-low \
  -H "Authorization: Bearer $API_KEY"

# { "id": "ainvented-low", "object": "model", "created": 1751328000, "owned_by": "ainvented" }

# An unavailable or unknown name returns 404:
# { "error": { "message": "The model 'not-a-tier' does not exist",
#              "type": "invalid_request_error", "param": "model", "code": "model_not_found" } }

Populate a model picker from the live list

import requests

BASE = "https://ainvented.com/api/v1"
headers = {"Authorization": "Bearer YOUR_API_KEY"}

models = requests.get(f"{BASE}/models", headers=headers).json()
for m in models["data"]:
    print(m["id"])       # ainvented-eon, ainvented-epic, ainvented-saga, ainvented-lite, ainvented-low

one = requests.get(f"{BASE}/models/ainvented-epic", headers=headers).json()
print(one["owned_by"])   # ainvented

# Any standard chat-completions client library works too: point its base URL at
# BASE and its "list models" call returns exactly the tiers above.

Details

The list reflects what your deployment can actually serve
Only tiers that are enabled here are listed. A tier that is not listed is not silently unavailable — if you pass it as model anyway it is accepted and served as ainvented-lite (and billed at that rate), exactly as any other unrecognised value is. Listing only enabled tiers means the list never promises a model you would not actually receive.

GET /api/v1/models/{model} accepts the same spellings as the model request field (hyphen or space form, case-insensitive).
POST/api/v1/chat/completions#

Create Chat Completion

Generate a chat completion response using your configured chat project. Supports both streaming and non-streaming modes.

Authentication

Bearer token required in Authorization header

Request Schema

JSON type shapeExpand
{
  "model": "string",
  "messages": [
    {
      "role": "string",
      "content": "string | ContentPart[]"
    }
  ],
  "temperature": "number",
  "max_tokens": "number",
  "max_completion_tokens": "number",
  "parallel_tool_calls": "boolean",
  "n, stop, logprobs, top_logprobs, seed, top_p, frequency_penalty, presence_penalty, user, metadata, store, service_tier, verbosity": "any",
  "reasoning_effort": "string",
  "response_format": "object",
  "include_reasoning": "boolean",
  "reasoning": "object",
  "system_authority": "string",
  "stream": "boolean",
  "stream_options": "object",
  "project_id": "string",
  "safety_identifier": "string",
  "prompt_cache": "boolean",
  "prompt_cache_ttl_hours": "string|integer",
  "session_id": "string",
  "run_workflow": "boolean",
  "tools": "array",
  "modalities": "array",
  "image": "object",
  "connector_id": "string",
  "connector_to": "string",
  "connector_media_type": "string",
  "connector_media_url": "string",
  "connector_media_filename": "string",
  "connector_email_subject": "string",
  "tool_choice": "string|object"
}
Fields32Expand
model
stringoptional
Selects the chat model tier. Every tier answers to more than one name, case-insensitively, so a client with a single free-text "Model ID" box works whichever one you type: the conversational model is 'ainvented-lite' or 'lite'; the lower-cost conversational model is 'ainvented-low' or 'low'; advanced reasoning is 'ainvented-saga' or 'saga'; the high-capability model is 'ainvented-epic' or 'epic'; our most capable model is 'ainvented-eon' or 'eon', where GET /v1/models lists it. When omitted, the project's preconfigured default model is used (or 'ainvented-lite' if the project has none). For compatibility with standard chat-completion clients, any other/legacy value is accepted (never rejected) and treated as 'ainvented-lite' — except the decision model ('ainvented-verdict' / 'verdict'), which does not chat: naming it is a 400 unsupported_model, free (send it to POST /v1/decisions instead). The response echoes the CANONICAL name of the tier you selected (so 'epic' comes back as 'ainvented-epic' and 'lite' as 'ainvented-lite'), never your raw string; pricing follows the selected tier (see the pricing page). A request that names no model on a project whose default is Lite (or that has none), or a value the API does not know (a typo included), is answered by the Lite tier under its earlier id, unchanged for compatibility — name 'ainvented-lite' to see it echoed. GET /v1/models is the authoritative list.
messages
array
array — fields below
role
stringrequired
'system' | 'developer' | 'user' | 'assistant' | 'tool'. 'developer' is another name for 'system' — the one current chat-completions clients use for the instructions message — and is read exactly like it: same place, same authority, same cache prefix. 'tool' carries a function's result in a function-calling loop (see Inline function tools). SIZE LIMIT: all `system` messages in a request are concatenated (in order, newline-separated) into the cached stable prefix. There is no longer a fixed character cap on any role; the whole request is instead fitted to the selected tier's INPUT TOKEN BUDGET, measured with the same tokenizer used for billing. Your `system` messages and your latest turn are the protected core and are never silently shortened: if they do not fit, the request is REFUSED with 400 context_length_exceeded (and is not billed) rather than answered from a truncated prompt. Lower-priority context (project files, workflow output) is trimmed first, and any trim at all is reported back on the `context_truncation` response field — nothing is dropped without telling you.
content
string | ContentPart[]required
Message content (text string or array of content parts for multimodal: `text`, `image_url`, `input_audio`, `video_url`).★ PUBLIC URL READING ("web search"): any public http(s) URL you include in the LAST user message's TEXT (e.g. 'summarize https://example.com/article') is automatically fetched and read by the assistant so it can answer about the page contents — no special parameter needed. CONTROLLED PER-PROJECT by the `web_search_enabled` setting (DEFAULT FALSE — opt in explicitly when you create or update the project — see POST / PUT /api/v1/projects). URLs typed in message text are NOT fetched unless the project sets web_search_enabled=true. SCOPE: detection runs on the message TEXT ONLY and is completely independent of file/image/audio handling — `image_url` content parts, attached project files, and audio are always forwarded regardless of this setting; only text-mentioned URLs are affected. data: URLs and images still go through `image_url` content parts. Adds no latency to plain text-only messages (URLs are fetched upstream only when present) and does not change billing. Works in non-streaming and streaming.★ A MESSAGE THAT IS ONLY A LINK TO AN IMAGE, AUDIO OR VIDEO FILE IS TREATED AS THAT FILE: when the whole content of the last user message is one http(s) link whose path ends in an accepted media extension (jpg, jpeg, png, gif, webp, bmp, tif, tiff, avif — wav, mp3, m4a, flac, ogg — mp4, m4v, mov, webm, mkv, 3gp, avi, mpg, mpeg, flv, wmv), the link is downloaded and attached exactly as if you had written it out as an `image_url` / `input_audio` / `video_url` content part, and it is billed exactly the same. A VIDEO link is promoted ONLY on a project with `web_search_enabled` = true (a video is downloaded, read and billed, so a project that keeps links unread — the default — gets its message as the text it was, nothing downloaded or billed). A promoted VIDEO that downloads but cannot be read is answered with a note saying so, never refused. The condition is strict: ONE link and nothing else — add a caption, a question, a second link or any other content part and the message keeps its current meaning (plain text, plus the URL reading above when the project enables it). A link that cannot be used — unreachable, private, oversized, or not the media its extension claimed — NEVER fails the request: the message stays exactly the text you sent, URL and all, and the turn runs precisely as it does today (including the URL reading above when your project enables it). No image or audio tokens are charged for a file that never arrived. For images and audio this is independent of `web_search_enabled` (a media link is an attachment, not a page to read); for a video it requires it (see above). It applies identically to streaming and non-streaming.
temperature
numberoptional
0.0 to 2.0, default: 1.0
max_tokens
numberoptional
Maximum tokens to generate. Forwarded to the model so generation STOPS at the cap (shorter responses arrive sooner); the reply is also clipped to it and `finish_reason` becomes 'length'. Each attempt is billed for at most the cap you set. On a forced function call (tool_choice 'required' or a named function) it counts the call's tokens exactly, as in the reference API, and a call the cap cuts is asked again once when its function lists required fields — that attempt is billed too — see Inline function tools.
max_completion_tokens
numberoptional
The same cap as max_tokens, under the name current chat-completions clients send for reasoning models; it behaves exactly like max_tokens (generation stops at it, finish_reason 'length', never billed past it). Read only when max_tokens is absent — a request that sends both is capped by max_tokens.
parallel_tool_calls
booleanoptional
Accepted, so a request written for a standard chat-completions client works unchanged — and not enforced: whatever its value, one assistant turn may carry several calls in tool_calls (for example one that records the customer's data and one that books their appointment). Handle every entry, in order.
n, stop, logprobs, top_logprobs, seed, top_p, frequency_penalty, presence_penalty, user, metadata, store, service_tier, verbosity
optional
Accepted, so a request written for a standard chat-completions client works unchanged, and not used: the reply is one choice, without log-probabilities, and no stop sequence cuts it — what ends a reply early is max_tokens (or max_completion_tokens). Sending them never changes the answer, the billing or the latency, and never returns an error.
reasoning_effort
stringoptional
How much reasoning to spend on this turn: 'low', 'medium', 'high', 'xhigh' or 'max'. The same five levels work on EVERY model tier. Omitting the field uses the selected tier's standard effort, so existing clients are unaffected; it behaves identically on streaming and non-streaming requests. For drop-in compatibility, 'minimal' and 'none' are also accepted and treated as 'low', and an explicit null is treated as if the field were omitted — so a request written against a standard chat-completions client works unchanged. Any other value returns 400 invalid_request_error with param="reasoning_effort", rejected before any model is called, so an invalid value never costs you anything. Reasoning tokens are billed INSIDE completion_tokens (never additional) and are surfaced under usage.completion_tokens_details.reasoning_tokens when the serving engine reports them. Because a higher effort spends more of the same max_tokens budget thinking, a capped request can return LESS visible text at 'max' than at 'low' — raise max_tokens alongside the effort. PRECEDENCE: this request field > the project's `preconfigured_effort` > the tier's standard effort. Image-generating requests always run at the standard effort.
response_format
objectoptional
Structured output. { type: 'text' } (the default — nothing changes), { type: 'json_object' } (the reply is ONE valid JSON object), or { type: 'json_schema', json_schema: { name: string, schema: object (JSON Schema), strict?: boolean, description?: string } } (with strict: true the reply validates against your schema; with strict false or omitted the schema guides the reply and the reply is guaranteed to be a valid JSON object). Works on every model tier, streaming and non-streaming. Every reply is validated before it is released; an invalid one is regenerated (bounded), and if no attempt matches you get 502 response_format_failed. Combines with `tools`: a turn may still call a tool (tool_calls as usual) and any prose next to the call is dropped so `content` stays JSON or null. A reply that does not fit your own max_tokens is cut at the cap with finish_reason 'length' (incomplete JSON, billed at most the cap — raise max_tokens). Not allowed with modalities: ['image'] (an image-only reply has no text to format) — 400. An invalid value is 400 invalid_response_format with param 'response_format', decided before any model runs (never billed).
include_reasoning
booleanoptional
Whether the model's reasoning is returned. STREAMING: on by default — reasoning arrives as `delta.reasoning_content` chunks before the answer, so a client on a long-thinking turn sees progress instead of an empty stream; send false to turn it off. NON-STREAMING: off by default; send true to get it as `choices[0].message.reasoning_content`. Reasoning is never part of `content`, never stored with the conversation, and never billed separately (reasoning tokens were always inside completion_tokens). A turn whose model does not reason returns no reasoning, and a very short think may come without a summary (its answer arrives within a couple of seconds anyway). A non-boolean value is 400 invalid_reasoning_option.
reasoning
objectoptional
Alternative spelling some clients use: { exclude: true } is the same as include_reasoning: false. Other keys are ignored. A non-object value, or a non-boolean `exclude`, is 400 invalid_reasoning_option.
system_authority
stringoptional
How your `system` messages relate to the platform's own prompt. DEFAULT BEHAVIOUR: whenever a request carries a `system` message, that message is AUTHORITATIVE — the platform's conversational framing, tone paragraph and chat scaffolding are not layered on top of it. Your project's configured agent prompt, RAG results, URL-derived context, project files and the user's message all still apply, as do the rules that keep the underlying model unnameable. A request with NO `system` message is unaffected. Send 'merge' to pin the previous behaviour for a request (the platform prompt wraps your instructions), or 'exclusive' to state the default explicitly. An unrecognised value is ignored rather than rejected.
stream
booleanoptional
Enable streaming response, default: false. Closing the connection before the stream ends stops the turn and bills what it generated up to the close: the input, and the output produced so far — reasoning included, since reasoning tokens are part of completion_tokens. When the close comes before the turn's usage was reported, that output is counted from what was streamed.
stream_options
objectoptional
streaming only — { include_usage: true } appends ONE final chunk before 'data: [DONE]' carrying the same `usage` object the non-streaming response returns. That chunk has an EMPTY choices array (choices: []) — the standard marker clients use to recognise it. Omit the field (or send anything other than exactly true) and the stream is byte-for-byte what it has always been, so existing streaming clients are unaffected. Costs no additional latency: the chunk is emitted after the last content delta.
project_id
stringoptional
Specific project ID (ignored if API key is scoped to a project)
safety_identifier
stringoptional
Accepted for drop-in compatibility with standard chat-completion clients, and IGNORED — sending it never changes the response, the billing or the latency, and it is never rejected. Abuse attribution on this platform is derived server-side from the authenticated project and account behind each request, so no client-supplied identifier is needed for it. The legacy `user` field is treated the same way. Per-END-USER attribution (distinguishing the individual people using YOUR application) is not currently exposed; if you need it, say so — the request field is reserved for exactly that.
prompt_cache
booleanoptional
default true — Prompt caching. When enabled (the default), repeated prompt prefixes across nearby requests are served from cache and those cached input tokens are billed at a heavily discounted cached rate (see Pricing), so your balance lasts longer at no quality cost. Set false to opt THIS request out — cached input tokens are then billed at the full input rate. PRECEDENCE: this request field > the project's `prompt_cache_enabled` setting > platform default (ON). Caching never changes the response text; the discount applies only when the provider reports a cache hit (not guaranteed for short prompts). Adds no latency.
prompt_cache_ttl_hours
string|integeroptional
Managed Prompt Cache: keep this project's stable prompt prefix (system/assistant instructions of at least 1,024 tokens) in a dedicated cache for a guaranteed lifetime, so EVERY request reusing it gets the cached-input discount deterministically (not best-effort). Allowed values: 1, 6, 12 or 24 (hours), "auto", or null — "auto"/null defer to the project's managed-cache setting for this request (same as omitting the field); any other value returns 400. The cached stable prefix INCLUDES your `system` role message(s) — so sending a large, unchanging system prompt bills it at the cached rate on every reuse instead of re-charging it each turn (different system prompts are cached separately and never collide). Billing: cached storage is charged at $1.50 per 1M tokens per hour (pro-rated per cached prefix) plus a one-time cache-write at $0.40 per 1M tokens; break-even guidance: the cache pays for itself above roughly 5 reuses of the prefix per hour. PRECEDENCE: this request field > the project's `prompt_cache_ttl_hours` setting. Requires prompt caching enabled (`prompt_cache:false` wins). Identical configuration and pricing across every model tier - switching models changes nothing.
session_id
stringoptional
Existing session ID for context continuity. If you already send the full conversation in `messages` (stateless usage — you manage history client-side), the server uses your transcript as the history and does NOT additionally load this session's stored history, so context is never duplicated. Send only the latest message + session_id to instead have the server supply the prior turns.
run_workflow
booleanoptional
Execute the project's configured workflow and inject results as context before generating the response. Default: false
tools
arrayoptional
Standard function-tool definitions for workflow override mode. When provided, only matching project workflows are executed. When omitted, all active project workflows auto-execute. An empty array disables all workflow execution. Format: [{ type: 'function', function: { name, description?, parameters? } }]. SPECIAL: a tool named 'image_generation' opts this request into image output (same as modalities: ['image']); its `parameters` are merged into the `image` block.★ TASKS (when the Tasks feature is enabled for your project): a tool whose `function.name` matches a stored Task (created via POST /api/v1/tasks) SELECTS that task for this interaction — standard tool selection. By default, selected tasks run ASYNCHRONOUSLY after the reply is flushed (zero TTFT/TTLT impact) and analyze the conversation history to extract structured data / classify intent; opting into `task_wait:true` instead runs them inline and adds their latency (see Result-delivery modes). A tools name matching no task/workflow/tool is ignored (no error). Read results via GET /api/v1/tasks/{id}/runs.★ PER-REQUEST GUARDRAILS AND SKILLS: besides functions, `tools` accepts typed entries that apply to THIS request only — { type: 'guardrail', guardrail: { rule: string, name?: string } } (or guardrail: '<rule text>') and { type: 'skill', skill: { prompt: string, name?: string, description?: string } } (or skill: '<prompt text>'). Or SELECT one of the project's stored guardrails or skills (made with the Guardrails & Skills endpoints, in AI Chat or in the Partner Console — the same ones) by id or name: { type: 'skill', skill: { name: 'Formal tone' } } or { type: 'guardrail', guardrail: { id: '<uuid>' } } — an inactive one applies to this request only; an active one already applies to every request. They are ADDED to the project's stored guardrails and skills (stored first, then these) and never replace or switch off a stored one. They are taken out of `tools` before anything else reads it, so an array holding only guardrails/skills behaves exactly as if `tools` were omitted (workflows keep auto-running, no task is selected). Up to 32 guardrails and 32 skills per request, 1,000,000 characters combined; they count as ordinary input tokens of the turn. A malformed entry is 400 invalid_guardrail / invalid_skill (param names the entry, e.g. tools[2].guardrail.rule), too many is 400 too_many_guardrails / too_many_skills, too large is 400 inline_directives_too_large, an id or name the project does not have is 400 guardrail_not_found / skill_not_found, a name two of them share is 400 ambiguous_guardrail / ambiguous_skill (select it by id) — all decided before any model is called, never billed.
modalities
arrayoptional
Output modalities hint. Allowed values: 'text' | 'image'.★ IMAGE GENERATION IS STRICTLY OPT-IN — when this field is OMITTED, the endpoint stays on the fast text-only path with the lowest TTFT/TTLT (no image-generation work is triggered). A first-time caller will always feel the fastest possible response. Semantics: omitted → text-only fast path (default); ['text'] → same as omitted, treated as explicit text-only; ['image'] → OPT-IN: image only (no text reply); ['text','image'] → OPT-IN: text + image for every request. Images returned by the model are still surfaced in response.images (subject to your project's image-generation setting).
image
objectoptional
Image-generation parameters. Applied only when 'image' is in modalities or a tool named 'image_generation' is provided. Fields: { n?: 1..4 (default 1), size?: '256x256'|'512x512'|'1024x1024'|'1024x1536'|'1536x1024'|'1024x1792'|'1792x1024' (default '1024x1024'; the generated image has exactly the requested size and aspect ratio), quality?: 'standard'|'hd' (default 'standard'; hd renders more detail and bills more output tokens), style?: 'vivid'|'natural' (default 'vivid'), response_format?: 'url'|'b64_json' (default 'url'), remove_background?: boolean (default false; available when background removal is enabled for your project) }. PRECEDENCE: per-request image.* > your project defaults (Configure pane) > built-in defaults. Per-request always wins.★ REFERENCE/PRODUCT IMAGES: any images you attach in the last user message's content as `image_url` parts (base64 data: URLs or http(s) URLs) are forwarded to the image generator as references, so it edits/uses YOUR product instead of inventing one. Works in both streaming and non-streaming.
connector_id
stringoptional
UUID of an active chat connector to ALSO dispatch the AI reply through (Telegram, WhatsApp, Slack, Email/Resend, Gmail, SMTP, Telnyx SMS). The /v1/chat/completions response is still returned normally; the connector dispatch is best-effort and non-fatal — a dispatch failure is logged but does not change the HTTP response.
connector_to
stringoptional
Recipient address for the connector dispatch. Format depends on the channel: '+15551234567' for SMS / WhatsApp / Telnyx, channel id like 'C0123456' for Slack, chat id integer for Telegram, RFC-822 email for Resend / Gmail / SMTP. Required when connector_id is set.
connector_media_type
stringoptional
Type of media to attach to the connector dispatch. Allowed: 'image' | 'audio' | 'voice' | 'document' | 'video'. Default 'image'. Only consumed when connector_media_url is also set.
connector_media_url
stringoptional
Explicit media URL to attach to the connector dispatch. Wins over auto-attach. When this field is omitted AND the response produced images, response.images[0] is auto-attached (when auto-attach is enabled for your project).
connector_media_filename
stringoptional
Filename for documents dispatched via document-capable connectors (Telegram document, email attachments). Only consumed when connector_media_type='document'.
connector_email_subject
stringoptional
Subject line for email/Gmail/SMTP dispatch. Defaults to a generic 'AI assistant reply' subject when omitted.
tool_choice
string|objectoptional
Standard tool-selection control, also used to control Tasks (when the Tasks feature is enabled for your project). Values: 'auto' (run task-tools named in `tools` PLUS any matching on_message/on_intent project tasks — an on_intent task auto-fires when the conversation matches one of its declared intents, e.g. cancel_order), 'none' (run no tasks), 'required' (run ONLY the task-tools named in `tools`), or { type: 'function', function: { name } } (run ONLY that one task). COST-SAFE DEFAULT: auto-trigger expansion (firing unnamed on_message/on_intent tasks) happens when tool_choice is EXPLICITLY 'auto'. If tool_choice is omitted, only the tasks you NAME in `tools` fire — an empty `tools:[]` or omitting both fields runs NO tasks by default (so passing tools:[] to disable workflows never incurs surprise task spend). TRANSPARENT AUTO-FIRE (opt-in per project): a project can be configured so an OMITTED tool_choice behaves as 'auto' — then a plain chat-completion request (no tools/tool_choice at all) automatically runs the project's on_message/on_intent tasks, so existing clients need no changes. Contact us to enable it for your project. By default task selection + execution are resolved asynchronously AFTER the reply (zero TTFT/TTLT impact); only the opt-in task_wait:true runs them inline and adds latency.

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "string",
  "created": "number",
  "model": "string",
  "choices": [
    {
      "index": "number",
      "message": {
        "role": "string",
        "content": "string | null",
        "tool_calls": "array (only when the model calls inline function tools)",
        "reasoning_content": "string (only with include_reasoning: true, and only when the model reasoned)"
      },
      "finish_reason": "string"
    }
  ],
  "usage": {
    "prompt_tokens": "number",
    "completion_tokens": "number",
    "total_tokens": "number",
    "prompt_tokens_details": "object",
    "completion_tokens_details": "object"
  },
  "response": {
    "images": "string[]",
    "image_meta": "object[] (only present when images were produced)"
  },
  "session_id": "string",
  "context_truncation": "object (present ONLY when part of the request had to be left out)"
}
Fields23Expand
id
string
Unique completion ID
object
string
'chat.completion'
created
number
Unix timestamp
model
string
Model used
choices
array
array — fields below
index
number
Choice index
message
object
object — fields below
role
string
'assistant'
content
string | null
Generated text. null when the model emits tool_calls (function calling).
tool_calls
array (only when the model calls inline function tools)
[{ id: string, type: 'function', function: { name: string, arguments: string (JSON-encoded) } }]. Present with finish_reason 'tool_calls'.
reasoning_content
string (only with include_reasoning: true, and only when the model reasoned)
The model's reasoning for this turn. Never part of `content`.
finish_reason
string
'stop' | 'length' (the reply reached max_tokens — with response_format the JSON is then incomplete) | 'content_filter' | 'tool_calls' (when the model called one or more inline function tools)
usage
object
object — fields below
prompt_tokens
number
Input tokens billed for this turn, including your messages, any attached project context, and any in-turn auxiliary work (URL extraction, image captioning, transcription).
completion_tokens
number
Output tokens billed for this turn.
total_tokens
number
prompt_tokens + completion_tokens.
prompt_tokens_details
object
{ cached_tokens: number } — the portion of prompt_tokens served from the prompt cache and billed at the discounted cached rate. A SUBSET of prompt_tokens, never additional. 0 when prompt caching is disabled for the project or the request.
completion_tokens_details
object
{ reasoning_tokens: number } — reasoning/'thinking' tokens, ALREADY INCLUDED in completion_tokens (never additional). 0 means the serving engine does not report them separately; those tokens are still billed inside completion_tokens.
response
object
object — fields below
images
string[]
URLs (or data: URLs) of any images generated by the model. Empty array when no images were produced or image generation is disabled. Image URLs are NEVER inlined as markdown in choices[0].message.content; they are always returned in this dedicated field.
image_meta
object[] (only present when images were produced)
One entry per URL in `images`, same order. Fields per entry: { url: string, size: '256x256'|...|'1792x1024', format: string|null, bytes: number|null, source: string (origin of the image, e.g. 'background_removed'), request_id: string (uuid identifying the originating request), prompt_excerpt: string (first 80 chars of the originating prompt) }.
session_id
string
Session ID for future requests
context_truncation
object (present ONLY when part of the request had to be left out)
The request did not fit the selected tier's input budget, so some of it was not sent to the model. Fields: { truncated: true, input_tokens_dropped: number, attached_context_truncated: boolean (project files / workflow output were cut), system_messages_truncated: boolean (your `system` messages were cut), messages_truncated: boolean (your user/assistant turn was cut) }. Absent on every request that fitted, so this is purely additive. A request that cannot be trimmed at all is refused with 400 context_length_exceeded instead (see Error Codes) and is NOT billed.

Code Examples

Basic completion request with non-streaming response

import requests

api_key = "your_api_key_here"
url = "https://ainvented.com/api/v1/chat/completions"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

data = {
    "model": "ainvented-lite",
    "messages": [
        {"role": "user", "content": "Hello, how are you?"}
    ],
    "temperature": 0.7,
    "max_tokens": 150
}

response = requests.post(url, headers=headers, json=data)
result = response.json()
print(result["choices"][0]["message"]["content"])

Streaming completion with Server-Sent Events

import json
import requests

api_key = "your_api_key_here"
url = "https://ainvented.com/api/v1/chat/completions"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

data = {
    "model": "ainvented-lite",
    "messages": [
        {"role": "user", "content": "Tell me a story"}
    ],
    "stream": True
}

response = requests.post(url, headers=headers, json=data, stream=True)
response.raise_for_status()

for line in response.iter_lines():
    if not line.startswith(b"data: "):
        continue
    payload = line[6:]
    if payload == b"[DONE]":
        break
    chunk = json.loads(payload)
    content = chunk["choices"][0]["delta"].get("content")
    if content:
        print(content, end="", flush=True)

Basic cURL example

curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ainvented-lite",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ],
    "temperature": 0.7
  }'

Using fetch API

const apiKey = "your_api_key_here";
const url = "https://ainvented.com/api/v1/chat/completions";

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${apiKey}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "ainvented-lite",
    messages: [
      { role: "user", content: "Hello, how are you?" }
    ],
    temperature: 0.7,
    max_tokens: 150
  })
});

const result = await response.json();
console.log(result.choices[0].message.content);

Details

Model tiers

Select the chat model per request with the model field (or set a project default via preconfigured_model). Most capable first, in two groups:

Agentic models — reasoning, tools and multi-step work:

  • ainvented-eon (or eon) — our most capable model, the top tier, where GET /api/v1/models lists it. Best for the hardest work. It works as a project default too (preconfigured_model), so channel replies, tasks and workflows run on it. In a long agent conversation (tool calls and their results), eon keeps what it reads short: once the conversation grows large, older tool output that has gone out of date — a file that changed after it was read, a command that ran again — is replaced by a short note saying so, while your request, what was read once and the latest results are kept; usage reports the tokens actually read.
  • ainvented-epic — a high-capability agentic model. Best for hard multi-step tasks.
  • ainvented-saga — an advanced reasoning agentic model. Best for complex analysis and long-form work.

Conversational models — fast, inexpensive chat:

  • ainvented-lite (or lite) — the fast conversational model, for everyday chat, assistants and support.
  • ainvented-low (or low) — the lowest-cost conversational model. Best for high-volume, cost-sensitive turns.
  • The bare words eon, epic, saga, lite and low are accepted too (case-insensitively), for clients whose settings offer a single free-text "Model ID" box. GET /api/v1/models/{id} accepts every one of these spellings and resolves it to the canonical entry.
  • Omitting model uses the project's preconfigured default (or ainvented-lite). Any unrecognized value is accepted and treated as ainvented-lite — never rejected.
  • The response model field echoes the canonical name of the tier you selected — epic comes back as ainvented-epic, lite as ainvented-lite, never your raw string. GET /api/v1/models is the authoritative list.

Each tier is billed per million tokens of input, cached input and output, at its own rates — most capable first (also on the pricing page):

TierInputCached inputOutput
Agentic models
Eon ainvented-eonOur most capable model$5.00$0.500$25.00
Epic ainvented-epicHigh-capability agentic model$4.00$0.800$20.00
Saga ainvented-sagaAdvanced reasoning agentic model$2.00$0.400$6.00
Conversational models
Lite ainvented-liteFast conversational model$0.30$0.060$1.50
Low-cost ainvented-lowLowest-cost conversational model$0.20$0.045$0.65

USD per 1M tokens, the current rates.

A very long ainvented-lite request — more than 272,000 input tokens — is billed at twice its input and cached-input rates and 1.5 times its output rate, for the whole request; every shorter request is billed at the rates above. usage reports the tokens billed.

Select how much reasoning each request gets with the reasoning_effort field (or set a project default via preconfigured_effort): low, medium, high, xhigh or max. Omitting it keeps the tier's standard effort, so a higher effort is always something you opt into — it buys answer quality with time-to-first-token and completion tokens. It applies identically to streaming and non-streaming requests.

  • The same five levels work on every tier.
  • For drop-in compatibility, reasoning_effort: "minimal" and "none" are also accepted and treated as low, and an explicit null is treated as if the field were omitted — so a request written against a standard chat-completions client works unchanged.
  • Any other value returns 400 invalid_request_error with param="reasoning_effort". It is rejected before the request reaches a model, so an invalid value never costs you anything.
  • Reasoning tokens are billed inside completion_tokens — never as an extra charge — and are reported under usage.completion_tokens_details.reasoning_tokens when they are reported separately.
  • A higher effort spends more of the same max_tokens budget thinking, so a capped request can return less visible text at max than at low. Raise max_tokens alongside the effort.
  • On ainvented-eon the reasoning is bounded at every effort, so even the hardest requests are answered in minutes; the answer itself is not shortened. Its reasoning is billed inside completion_tokens, as on every tier.
Every tier reads images — and is billed at its own rates
Every tier reads images as well as text, streaming or not, at every effort. Each tier is billed at its own rates (see the pricing page); requests to ainvented-saga that include images are billed at the ainvented-epic rate. An ainvented-eon turn is always billed at the ainvented-eon rate. The response model field echoes the tier you asked for.
cURL — request the low tier
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"model":"ainvented-low",
       "messages":[{"role":"user","content":"Summarize: the meeting is moved to 3pm Friday."}]}'
# -> response.model is ainvented-low; the turn is billed at the ainvented-low rate
cURL — ask the most capable model (Eon)
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"model":"ainvented-eon",
       "reasoning_effort":"high",
       "messages":[{"role":"user","content":"Design a rate limiter for a public API, with code."}]}'
# -> response.model is ainvented-eon; the turn is billed at the ainvented-eon rate

Streaming Response

When stream: true is set, the response uses Server-Sent Events (SSE). Each chunk follows this schema:

Example
{
  "id": "string - Unique completion ID",
  "object": "string - 'chat.completion.chunk'",
  "created": "number - Unix timestamp",
  "model": "string - Model used",
  "choices": [
    {
      "index": "number - Choice index",
      "delta": {
        "role": "string (optional) - 'assistant' (first chunk only)",
        "content": "string (optional) - Incremental text content",
        "reasoning_content": "string (optional) - Incremental reasoning, streamed BEFORE the answer while the model thinks (on by default for streams; include_reasoning: false turns it off). Comes in its own chunks — never in the same chunk as `content` — so a client that ignores unknown delta keys sees exactly the stream it always did.",
        "tool_calls": "array (optional) - Inline function-calling deltas: [{ index: number, id: string, type: 'function', function: { name: string, arguments: string } }]. Accumulate by `index`; the stream ends with a finish_reason 'tool_calls' chunk.",
        "images": "string[] (optional) - Emitted in a dedicated chunk when the model generates one or more images. URLs (or data: URLs). Never inlined as markdown in delta.content.",
        "image_meta": "object[] (optional) - Emitted IMMEDIATELY AFTER the delta.images chunk when the caller opted in via modalities/image. Same per-entry shape as response.image_meta (url, size, format, bytes, source, request_id, prompt_excerpt). Old clients can safely ignore unknown delta.* keys."
      },
      "finish_reason": "string | null - 'stop' (final text chunk), 'tool_calls' (after inline function-call deltas), else null"
    }
  ],
  "session_id": "string (final chunk only) - Session ID for future requests",
  "context_truncation": "object (final chunk only, and only when part of the request had to be left out) - Same shape as the non-streaming `context_truncation` field. It rides the FINAL chunk because the upstream reports the trim after the generated text."
}

Streaming reasoning

On a reasoning turn the model can think for a while before the first word of the answer. A stream (stream: true) now carries that reasoning as it happens, in delta.reasoning_contentchunks, followed by the answer in delta.content as always — the convention coding agents and chat clients already render as "thinking". Nothing to enable.

  • Turn it off per request with include_reasoning: false (or reasoning: {"exclude": true}). Off, the stream is exactly what it was before.
  • Non-streaming requests return reasoning only when asked: include_reasoning: true adds choices[0].message.reasoning_content.
  • Reasoning is never part of content, never stored with the session, and never changes the bill: reasoning tokens were always counted inside completion_tokens (usage.completion_tokens_details.reasoning_tokens).
  • A turn whose model does not reason (low effort, a short answer) has no reasoning chunks. A higher reasoning_effort produces more of them.
  • While a stream has sent nothing for 15 seconds — a model thinking silently — an SSE comment line : keep-alive is written so proxies and client idle timers keep the connection open. Every SSE parser ignores comment lines.
  • A request that is not streamed sends nothing until the whole answer is ready. On a turn that can reason for minutes — the hardest questions on the reasoning tiers — stream it: a connection that carries nothing for 6 minutes is closed (504) before the answer arrives.
Stream — reasoning, then the answer
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"reasoning_content":"The user wants the total. 3 boxes of 12 is 36…"},"finish_reason":null}]}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"There are 36 items."},"finish_reason":null}]}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Structured output (response_format)

Ask for JSON and get JSON. response_format takes the standard three forms and works on every tier, streaming or not:

  • {"type": "text"} — the default. The request is handled exactly as if the field were absent.
  • {"type": "json_object"} — the reply is one valid JSON object. Describe the keys you want in your messages.
  • {"type": "json_schema", "json_schema": {"name": …, "schema": {…}, "strict": true}} — the reply validates against your JSON Schema (types, required keys, enums, nested objects and arrays). Strict schemas follow the usual rules: every property listed in required and additionalProperties: false on each object; a schema that breaks them is a 400 invalid_response_format (param: response_format) that names every problem found — up to five, with where each is — so you fix them in one go. With strict false or omitted the schema guides the reply and you are guaranteed a valid JSON object.

Every reply is checked before it is released. A reply that does not match is generated again — a bounded number of times — and if none matches the request fails with 502 response_format_failed (retryable). The generations that were made are billed like any other turn; a request that is refused before reaching a model (an invalid response_format) costs nothing.

  • Streaming: the JSON arrives as ordinary delta.content chunks. Accumulate them and parse at the end.
  • With tools: the model may still call a tool; you get tool_calls as usual and any prose next to the call is dropped, so content is always JSON or null.
  • max_tokens: your cap wins over the JSON: a reply that does not fit is cut at the cap with finish_reason: "length" (incomplete JSON, billed at most the cap). Leave room.
  • Images: modalities: ["image"] (image-only) cannot be combined with a JSON format — 400.
  • The JSON is returned byte-for-byte as generated: no footer, link rewriting or truncation notes are added to a JSON reply.
cURL — extract fields as a strict schema
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"model":"ainvented-low",
       "messages":[{"role":"user","content":"Ana Gómez, 34, lives in Bogotá and works as an architect."}],
       "response_format":{"type":"json_schema","json_schema":{"name":"person","strict":true,
         "schema":{"type":"object","additionalProperties":false,
           "required":["name","age","city"],
           "properties":{"name":{"type":"string"},"age":{"type":"integer"},"city":{"type":"string"}}}}}}'
# -> choices[0].message.content = {"name":"Ana Gómez","age":34,"city":"Bogotá"}

Coding agents & other standard chat-completions clients

This endpoint is a drop-in target for any client that speaks the standard chat-completions protocol. Point the client's Base URL at https://ainvented.com/api/v1, paste an API key, and set the Model ID to one of the tiers above.

Model ID
Use ainvented-eon, our most capable model, where GET /api/v1/models lists it — or ainvented-epic, ainvented-saga, ainvented-lite or ainvented-low. The bare words eon, epic, saga, lite and low also work. Anything else is not a tier selection: it is accepted and treated as ainvented-lite.GET /api/v1/models returns exactly the ids you can use.

Agent clients differ from chat clients in one way that matters: they ship a largesystem prompt that defines a strict response protocol — "every reply must be exactly one tool call", replies formatted as tagged blocks — and they reject any reply that does not follow it, re-sending the whole conversation as a retry. For those clients the caller's system prompt must be the only thing shaping the answer, and it is:

  • Whenever a request carries a system message, that message is authoritative: the platform's conversational framing and tone rules are not layered on top of it. You do not have to ask for this and there is nothing to configure.
  • Your project's configured agent prompt still applies, ahead of your per-request instructions, so anything you set up in the project is preserved and your request wins on any point the two disagree about.
  • Native function tools work exactly as before, and tool_calls come back in the usual shape — the two are independent.
  • Send system_authority: "merge" on a request to pin the previous behaviour.

Screenshots and other images an agent attaches are accepted as image_url content parts in JPEG, PNG, GIF, WebP, BMP, TIFF or AVIF (an editor or browser screenshot is usually WebP). An unsupported format is a 400, not a retryable error — retrying the same image will not help; convert it first.

cURL — an agent-style request
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"model":"ainvented-epic",
       "stream":true,
       "stream_options":{"include_usage":true},
       "messages":[
         {"role":"system","content":"You are an agent. Every reply MUST be exactly one <tool> block and nothing else."},
         {"role":"user","content":"List the files in the project root."}
       ]}'

Session Management

Use the session_id parameter to maintain conversation context across requests:

  • First request — omit session_id; the response returns a new session ID.
  • Subsequent requests — include that session_id to continue the conversation.
  • Sessions are tied to your API key and keep the full conversation history.
  • Two ways to do multi-turn — pick one, don't combine them:
    • Stateless (recommended) — send the entire messages array (all prior turns + the new one) on every request. Your transcript IS the conversation history; the server does not add any stored history on top of it.
    • Stateful — send only the latest user message in messages plus the session_id; the server supplies the earlier turns from its store.
  • You don't need to do both: if messages already contains prior turns, the server automatically will not also re-load the stored session history, so context is never duplicated or double-counted toward usage. (Sending the full transcript AND relying on the stored history would otherwise repeat the same turns.)
  • /v1/chat/completions does not generate or expose chat session titles. (Title generation is suppressed upstream to minimize latency and cost.) Use the session_id returned in the response to correlate multi-turn conversations.

Project Selection

The API determines which project to use in this priority order:

  1. The API key's associated project (if scoped) — takes precedence over everything else.
  2. The project_id request field — only when the key is not scoped to a project.
  3. Your default project (first created).
Note
If your API key is scoped to a project, that project is always used and any project_id in the request is ignored — this enforces access control.

Project Enhancements: Skills & Guardrails

Every request automatically inherits the active Skills and Guardrails of its project — injected as standing instructions on every call, in the chat UI and in the Completions API alike. Manage them in AI Chat or with the Guardrails & Skills endpoints.

🎯 Skills

Instruction presets that shape the AI's behaviour on every response (e.g. "always respond in bullet points"). Set via the Skills button in AI Chat or POST /api/v1/projects/{projectId}/skills.

🛡️ Guardrails

Content/tone rules that are always enforced (e.g. "never mention competitors"). Set via the Guardrails button in AI Chat or POST /api/v1/projects/{projectId}/guardrails.

Per request. Add guardrails and skills to ONE request by sending them in tools, next to (or instead of) your functions. Any key can do it — including a project-scoped key that cannot touch the project's stored ones — and nothing is stored.

cURL — a guardrail and a skill for this request only
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "Can I get a discount on the annual plan?"}],
    "tools": [
      {"type": "guardrail", "guardrail": {"name": "no-discounts", "rule": "Never promise discounts or refunds; offer to connect the customer with sales."}},
      {"type": "skill", "skill": {"name": "tone", "prompt": "Answer in two short sentences, in the language of the question."}},
      {"type": "guardrail", "guardrail": "Never ask for card numbers."}
    ]
  }'
# Only guardrails and skills in tools: workflows and tasks behave as if tools were omitted.
# Nothing is stored; the project's own guardrails and skills still apply first.

Select a stored one. Pick any of the project's guardrails and skills — whether made with the endpoints below, in AI Chat or in the Partner Console — by name or id: {"type": "skill", "skill": {"name": "Formal tone"}}. An inactive one applies to that request only, so a project can keep a library of on-demand skills and rules switched off and choose them per request; an active one already applies to every request. Names match ignoring case and spacing; an unknown one is 400 skill_not_found / guardrail_not_found, a name two of them share is 400 ambiguous_skill / ambiguous_guardrail — select it by id (from GET /api/v1/projects/{projectId}/skills).

cURL — select stored ones by name and id, plus one for this request
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "A customer asks for a discount on their renewal. Write a two-sentence reply."}],
    "tools": [
      {"type": "skill", "skill": {"name": "Formal tone"}},
      {"type": "guardrail", "guardrail": {"id": "3f1c2b4a-5d6e-4f70-8a9b-0c1d2e3f4a5b"}},
      {"type": "guardrail", "guardrail": "Never ask for card numbers."}
    ]
  }'
# A stored one that is INACTIVE applies to this request only: keep a library of
# on-demand skills and rules switched off, and pick them per request.
# An ACTIVE one already applies to every request; selecting it changes nothing.
# Names match ignoring case and spacing. Unknown: 400 skill_not_found (param tools[0].skill.name).

The full guide — the three ways side by side, finding a name or an id, every error and what to do — is Guardrails & Skills → Use them in a chat request.

Additive, never a bypass
Per-request entries join the project's stored guardrails and skills for that request — stored first, then yours, in the same blocks. They cannot replace, reorder or switch off a stored one: a project's guardrails are its owner's, and only an Admin key can change them. A tools array that holds only guardrails and skills behaves exactly as if tools were omitted, so workflows and tasks are unaffected.
Billing
Guardrails and skills are part of the turn's input, so they are billed as input tokens on every request that carries them (stored ones on every request of the project). They ride with your message, after the cached prefix, so a large and stable instruction set is cheaper as a system message.

Workflow Execution in Chat

Set run_workflow: true to run the project's configured workflow before the AI responds. The workflow output is injected as context so the AI can reason over real-time data from your pipeline.

cURL — workflow-backed completion
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Summarise the latest results"}
    ],
    "run_workflow": true
  }'
Python — workflow-backed completion
import requests

api_key = "your_api_key_here"
url = "https://ainvented.com/api/v1/chat/completions"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

# run_workflow: true triggers the project workflow before the AI responds.
# The workflow output is injected as context so the AI can reason over real data.
data = {
    "messages": [
        {"role": "user", "content": "Summarise the latest results"}
    ],
    "run_workflow": True
}

response = requests.post(url, headers=headers, json=data)
result = response.json()
print(result["choices"][0]["message"]["content"])
How it works
With run_workflow: true, the project's workflow graph runs first and its end-node output is placed in the per-turn context the model reads, right before your message (the user message is available as the user_message input). Workflow errors are non-fatal — the AI still responds normally. Billing: this context is per-turn, so unlike your system messages it is not part of the cached stable prefix and is billed as ordinary input tokens on every request that carries it. Attached project files reach the model through the same per-turn context and bill the same way.

Tools Override (Selective Workflow Execution)

By default, all active project workflows run on every request and their output is injected as context. Use the tools field to control which run:

Default

No tools field → all active workflows auto-run (same as the chat UI).

Override

A tools array of names → only matching workflows run. Names look like workflow_<name>.

Disable

Pass "tools": [] → no workflows run for this request. Skills and guardrails still apply.

Only function entries take part in this. guardrail and skill entries (see Skills & Guardrails) are taken out first: a tools array with nothing else in it is the default, not an override.

cURL — selective workflow execution
# Only execute specific workflows (override mode)
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "tell me about Croatia"}
    ],
    "tools": [
      {"type": "function", "function": {"name": "workflow_country_cities"}}
    ]
  }'
Python — selective workflow execution
import requests

api_key = "your_api_key_here"
url = "https://ainvented.com/api/v1/chat/completions"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

# Override mode: only execute specific workflow tools
# Pass an empty tools array to disable all workflow execution
data = {
    "messages": [
        {"role": "user", "content": "tell me about Croatia"}
    ],
    "tools": [
        {"type": "function", "function": {"name": "workflow_country_cities"}}
    ]
}

response = requests.post(url, headers=headers, json=data)
result = response.json()
print(result["choices"][0]["message"]["content"])
Guide

Tasks — async history analysis

Tasks are reusable, client-defined units that asynchronously analyze a conversation's history to extract structured data or classify intent — without ever affecting the chat reply's latency. A task is an instruction prompt + a JSON-Schema output_schema + a trigger. Manage them via the REST endpoints below, and select them per interaction with the completions tools/tool_choice params (a task is a function tool referenced by name). Available when the Tasks feature is enabled for your project.

Endpoints

POST/api/v1/tasks
Create a task. Body: name, instructions, trigger_type, output_schema, and optional trigger_config, history_scope, model, action, enabled, scope. model is the tier the task's runs are served on (ainvented-eon where it is offered, ainvented-epic, ainvented-saga, ainvented-lite or ainvented-low; aliases accepted as on /v1/chat/completions); omitted, the project's preconfigured_model applies, then the Lite tier. Runs use the project's preconfigured_effort. (See Triggers and Limits below.)
GET/api/v1/tasks
List tasks. Filters: status, trigger_type, enabled, limit, after. Your global tasks are included by default — pass ?include_global=false for project-only, or ?scope=global for globals only. Each task carries scope.
GET/api/v1/tasks/{id}
Retrieve one task.
PUT/api/v1/tasks/{id}
Update a task — including pause/resume via enabled.
DELETE/api/v1/tasks/{id}
Delete a task. It stops running at once.
POST/api/v1/tasks/{id}/run
Run a task synchronously now and return the completed run with its result. Body: messages?, session_id?, project_id?. Used by the tool_call delivery mode and for run-now / testing. Runs regardless of the task's enabled flag (manual operator override — enabled:false only pauses automatic triggers); the run is billed and audited normally.
GET/api/v1/tasks/{id}/runs
Run history — each run has result, status, confidence, request_id, source_session_id, prompt_tokens/completion_tokens, completed_at. Filter to one conversation with ?session_id=…. (See Reading results.)

Triggers

A task's trigger_type decides when it can run:

  • manual — only runs when you explicitly name it (in tools) or call /run.
  • on_message — auto-runs on each interaction under tool_choice:'auto' (or on every request when transparent auto-fire is enabled for the project).
  • on_intent — trigger_config: { intents: [...] }. Under tool_choice:'auto' (or transparent auto-fire) the task auto-fires when the conversation matches one of its declared intents (e.g. cancel_order, refund). You can also name it explicitly in tools to force it on any turn. The check that decides whether a turn matches is billed as input tokens at the model that turn runs on — the model you send, or the project's default when you send none — a turn with images included.
  • schedule — trigger_config: { cron, timezone?, session_id? }.
The schedule trigger is currently unavailable
Creating or switching a task to trigger_type:'schedule' returns 400 schedule_disabled. Use on_message, on_intent, or manual meanwhile.

Scope — project vs. global

scope defaults to 'project'. Set it to 'global' to make the task available to all of your projects (it's user-scoped, so project_id is null).

A global task fires in /v1/chat/completions only when its name is explicitly listed in tools — it's never auto-expanded by on_message/on_intent under tool_choice:'auto' (that stays project-local). When it runs, the run binds to the calling project. A global task may not use trigger_type:'schedule' (no calling project at cron time) → 400 invalid_schedule_scope.

Selecting tasks from a completion

Name a task as a function tool — "tools":[{"type":"function","function":{"name":"<task name>"}}] — controlled by tool_choice (auto / none / required / {type:'function',function:{name}}). With both tools and tool_choice omitted, no tasks run by default (the cost-safe default). The project is resolved from your API key (or the project_id field) exactly like the rest of the endpoint — you never put a project id inside tools, and a task name resolves within the resolved project.

Transparent auto-fire (opt-in per project)
A project can be configured so an omitted tool_choice behaves as 'auto'. Then a plain chat-completion request — only model + messages, no tools or tool_choice — automatically runs the project's on_message/on_intent tasks. This lets existing chat-completion clients use Tasks with zero code changes. Contact us to enable it for your project. (Global tasks still fire only when explicitly named, even with auto-fire on.)

Inline function tools (standard function calling)

Separate from stored Tasks, you can use standard function calling: pass full function definitions inline on every request and let the model decide when to call them. Nothing is stored — if you don't send a definition on a request, it doesn't exist for that request.

  • Define functions in tools: {type:"function", function:{name, description, parameters /* JSON Schema */}}.
  • tool_choice: auto (model decides), none (never call), required (must call one), or {type:"function",function:{name}} (force one).
  • When the model calls a function, the reply has finish_reason:"tool_calls", message.content:null, and message.tool_calls[] (each with function.arguments as a JSON string). Parallel calls are supported: a turn may carry several calls, whatever parallel_tool_calls says — handle every entry of tool_calls.
  • You execute the function and continue the standard loop: resend with the prior {role:"assistant", tool_calls:[…]} and a {role:"tool", tool_call_id, name, content} result. The model then answers using the result.
  • Works with stream:true (tool calls arrive as delta.tool_calls then a final finish_reason:"tool_calls" chunk).
  • A forced call that comes back without its arguments is asked again. When you force a call (tool_choice:"required" or {type:"function",function:{name}}) and the reply's call carries none of the function's required arguments — or arrives cut — the platform asks once more, automatically, which adds a few seconds to that request. You receive the call when it carries its arguments; otherwise the first one. That extra work is billed as its own charge under the same X-Request-Id, in tokens of the model you selected in proportion to its cost; the response's usage includes it, and Observe shows it as a second trace marked Retry. A project with no budget left is never asked again. Calls that carry some of their arguments, auto calls and functions without required arguments are never asked again.
  • On a forced call, max_tokens counts tokens. When you force a call and set max_tokens, the model stops generating at that many tokens, the way max_tokens works in the reference API — the markup the platform puts around a call is not counted against it. A call that does not fit arrives cut and is asked again as described above, so leave room for your longest arguments. Without max_tokens, and on auto calls and plain text, nothing changes.
cURL — function-calling loop
# 1) Model decides to call get_weather
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"model":"ainvented-lite",
       "messages":[{"role":"user","content":"Weather in Paris?"}],
       "tools":[{"type":"function","function":{"name":"get_weather",
         "description":"Get current weather",
         "parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}],
       "tool_choice":"auto"}'
# -> finish_reason "tool_calls"; message.tool_calls[0].function.arguments is a JSON string

# 2) Run the function yourself, then send the result back to finish the turn
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"model":"ainvented-lite","messages":[
       {"role":"user","content":"Weather in Paris?"},
       {"role":"assistant","content":null,"tool_calls":[{"id":"call_1","type":"function",
         "function":{"name":"get_weather","arguments":"{\"city\":\"Paris\"}"}}]},
       {"role":"tool","tool_call_id":"call_1","name":"get_weather","content":"18C, sunny"}]}'
# -> a normal answer that uses "18C, sunny"
Inline tools vs. stored Tasks
Inline function tools are model-driven and ephemeral (you run the function and feed the result back). Stored Tasks are server-side history-analysis units you create once and reference by name. A tools entry whose name matches a stored Task is treated as that Task; any other function definition is an inline tool.

Result-delivery modes

How you get a task result back from /chat/completions:

async (default)
Task runs after the reply is flushed; fetch the result via /runs or a webhook. Zero TTFT/TTLT impact.
task_wait: true (opt-in)
The endpoint awaits the selected task(s) and returns them inline — a top-level task_results array (non-streaming), or a final delta.task_results SSE chunk before [DONE] (streaming). Adds the task's latency by choice.
task_mode: "tool_call"
Returns the task as a proposed tool_calls with finish_reason:"tool_calls" — no AI call is made. You execute it via POST /api/v1/tasks/{id}/run and continue the standard tool loop with a {role:"tool", ...} message. Honors stream:true; takes precedence over task_wait.

Reading results & delivery (action)

After a completion selects a task, poll GET /api/v1/tasks/{id}/runs?session_id=… using the session_id the completion returned (it matches the run's source_session_id). A run with status:"success" is done. A run stuck running past ~10 min is auto-failed to error (timed_out) — just re-trigger.

Or have the result pushed when the run finishes via the task's action:

  • action.webhook_url — POSTs the structured payload (must be a public http(s) URL; private/loopback/metadata addresses are rejected for SSRF safety).
  • action.connector_id + action.connector_to — sends via a project chat connector (Telegram / WhatsApp / SMS / Email / Gmail / SMTP).
  • action.min_confidence — gates delivery (results below it are stored but not pushed).

Webhook takes precedence when both are set; delivery is best-effort and never affects the stored run. The delivered flag on each run reflects the outcome.

history_scope & limits

history_scope controls how much of the conversation the task reads:

  • { mode: 'full' } (default) — the entire transcript, with automatic map-reduce over long histories (bounded to the most recent ~144k tokens to cap per-run cost).
  • { mode: 'last_n', n: <1..1000> } — only the last N messages.
  • { mode: 'since', since: '<ISO>' } — falls back to full for the standard message shape (no per-message timestamps).

Limits: name ≤120 chars, unique per project (or per account for global tasks) and not a reserved name like image_generation; on a name clash the project-local task wins for that project. instructions ≤20000 chars; metadata ≤16 keys; output_schema nesting ≤32 levels. Unknown fields are rejected (strict).

Cost & quotas

Every task AI call is metered (one usage event per AI call); CRUD makes no AI call. Per-project guardrails cap active tasks and runs per minute & per day — over the cap, runs are skipped (no spend) and task creation returns 429 task_quota_exceeded.

Each run carries the tokens it was charged for on prompt_tokens and completion_tokens, so GET /api/v1/tasks/{id}/runs reconciles 1:1 with what the project's consumption reports for those runs. A run that never reached the model — refused by the budget gate, or a task that no longer exists — reports 0, which is exactly what it cost. A retried run reports the sum of its attempts.

Error codes

feature_disabled (403) — Tasks not enabled for this project.
task_not_found (404) — task id not found / not owned by your project.
invalid_request_error (400) — bad payload, invalid output_schema / cron / trigger_config. Includes schedule_disabled (schedule trigger is off) and invalid_schedule_scope (a global task can't use the schedule trigger).
task_quota_exceeded (429) — active-task cap reached.
duplicate_task_name (409) — a non-deleted task with that name already exists in the same scope (per project, or per account for global tasks). A deleted task's name becomes reusable.
An unknown task name in tools is silently ignored (not a 4xx) — selection resolves asynchronously after the reply.
Guide

Multimodal Content Support

The Chat Completions API supports multimodal content including base64-encoded images and audio files. You can send images and audio alongside text in your messages using the ContentPart array format.

Image Generation — Request

Image output is opt-in per request: add "image" to modalities (or a tool named image_generation) and describe the picture in the last user message. Everything else is the same chat-completions call, so any standard chat-completions SDK works unchanged. Size, quality and count live in the optional image block; anything you leave out falls back to the project's image defaults (the chat's Configure pane), then to 1024x1024, standard, one image.

cURL — one image
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{
    "modalities": ["image"],
    "image": { "size": "1024x1536", "quality": "standard" },
    "messages": [{"role": "user", "content": "A minimalist poster of a cat astronaut floating above the Moon, flat colors"}]
  }'
# -> choices[0].message.content is a short note ("Generated 1 image."),
#    response.images[0] is the picture, usage counts the image tokens (see below)
JavaScript — any standard chat-completions SDK
const res = await client.chat.completions.create({
  model: 'ainvented-lite',
  modalities: ['image'],
  image: { size: '1024x1536' },            // optional: size, quality ('standard' | 'hd'), n (1-4)
  messages: [{ role: 'user', content: 'A minimalist poster of a cat astronaut floating above the Moon' }],
});
const [picture] = res.response.images;    // an https:// or data: URL — accept both
console.log(res.usage.completion_tokens_details.image_tokens);
Python — a standard SDK forwards the extra fields through extra_body
res = client.chat.completions.create(
    model="ainvented-lite",
    extra_body={"modalities": ["image"], "image": {"size": "1024x1536"}},
    messages=[{"role": "user", "content": "A minimalist poster of a cat astronaut floating above the Moon"}],
)
picture = res.model_extra["response"]["images"][0]   # an https:// or data: URL
print(res.usage.completion_tokens_details.image_tokens)
  • image.size: 256x256, 512x512, 1024x1024, 1024x1536, 1536x1024, 1024x1792 or 1792x1024 — the picture comes back at exactly that size. quality: standard or hd (more detail, more output tokens). n: 1 to 4 pictures per call.
  • Reference images: attach pictures as image_url parts of the last user message and the model edits or uses them (a product shot, a logo) instead of inventing one; their input tokens are billed at the image-input rate.
  • Usage: an image turn's usage counts the pictures too — inside prompt_tokens / completion_tokens, itemised as prompt_tokens_details.image_tokens and completion_tokens_details.image_tokens — so what you read there is what the ledger charged. A text turn's usage is unchanged.
  • Where the picture is: response.images (or the streaming delta.images chunk). Each entry is a URL your client can load or fetch: today an inline data:image/png;base64,… URL for both response_format values, so treat https:// and data: alike. A 1024² standard image answers in about 12 s, an hd portrait in about 25 s.
  • image.remove_background answers a transparent PNG when background removal is enabled for the deployment; otherwise the flag is accepted and ignored.

Image Generation — Response Shape

When the model produces one or more images (e.g. a project configured for image generation, an image-modification workflow, or a text-to-image prompt), URLs to the generated images are returned in a dedicated field. Image URLs are never inlined as markdown in choices[0].message.content / delta.content.

Non-streaming (stream=false)

The top-level response includes a response.images array. Empty when no images were generated.

Non-streaming (stream=false)
{
  "id": "chatcmpl-1736541234567",
  "object": "chat.completion",
  "created": 1736541234,
  "model": "ainvented-lite",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Here is the rendered image you requested."
      },
      "finish_reason": "stop"
    }
  ],
  "response": {
    "images": [
      "https://cdn.ainvented.com/generated/abc123.png",
      "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
    ]
  },
  "session_id": "sess_abc123"
}

Streaming (stream=true)

Generated images arrive in a dedicated chunk whose choices[0].delta is { images: string[] }. This chunk is interleaved with normal text-delta chunks; one chunk per batch of generated images. The final chunk has finish_reason: "stop" and a top-level session_id, followed by data: [DONE].

Streaming (stream=true)
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1736541234,"model":"ainvented-lite","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1736541234,"model":"ainvented-lite","choices":[{"index":0,"delta":{"content":"Here is the rendered image you requested."},"finish_reason":null}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1736541234,"model":"ainvented-lite","choices":[{"index":0,"delta":{"images":["https://cdn.ainvented.com/generated/abc123.png"]},"finish_reason":null}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1736541234,"model":"ainvented-lite","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"session_id":"sess_abc123"}

data: [DONE]

Client tip: while iterating SSE chunks, treat delta.content (string) and delta.images (array) as independent fields that may appear in different chunks. Append delta.content to your running text buffer; collect delta.images into a separate array.

Content Types

Text Content

Text Content
{
  "type": "'text'",
  "text": "string - Text content"
}

Image Content (URL or Base64)

Image Content (URL or Base64)
{
  "type": "'image_url'",
  "image_url": {
    "url": "string - THREE ACCEPTED FORMS, detected automatically from the value: (1) an http(s) URL, (2) a data URL (data:image/<format>;base64,<data>), or (3) bare base64 with no prefix. Base64 can never begin 'http://' or 'data:' — ':' is outside the base64 alphabet — so the detection is exact, not a guess. Accepted formats: jpeg, png, gif, webp, bmp, tiff, avif — the same set for all three forms. Anything other than jpeg/png is converted losslessly on ingest at its ORIGINAL dimensions, so the same picture costs the same input tokens whichever format you send it in. An http(s) URL is identified from the BYTES it returns, not from its Content-Type header, so a correct image served as 'application/octet-stream' works and an HTML error page served as 'image/png' does not. That download is capped at the same size limit as an inline image and is abandoned as soon as it passes it. A URL must be publicly reachable: private, loopback and cloud-metadata addresses are refused (invalid_url). An unaccepted format or an oversized file is a 400 (unsupported_format / image_too_large) and is never billed; a value that is none of the three forms is a 400 (invalid_image_url); a URL that is simply unreachable is skipped and the rest of the message is answered. BILLING IS IDENTICAL ACROSS THE THREE FORMS — a linked image costs exactly what the same image costs inline. You can also skip this part entirely: a user message whose WHOLE content is one image link is promoted to exactly this part for you (see `messages[].content`).",
    "detail": "string (optional) - 'auto' | 'low' | 'high' - Image detail level for token calculation"
  }
}

Supported formats: JPEG, PNG, GIF, WebP, BMP, TIFF, AVIF
Size limit: 20MB (configurable)
Detail levels: 'low' (85 tokens), 'high' (tile-based), 'auto' (automatic)
Note: anything other than JPEG/PNG is converted losslessly on ingest, keeping its original dimensions — so the same picture costs the same input tokens in any accepted format. Animated GIF/WebP contribute their first frame.

Audio Content (URL or Base64)

Audio Content (URL or Base64)
{
  "type": "'input_audio'",
  "input_audio": {
    "data": "string - THREE ACCEPTED FORMS, detected automatically from the value, exactly as for image_url.url: (1) an http(s) URL to the audio file, (2) a data URL (data:audio/<format>;base64,<data>), or (3) bare base64. A URL is downloaded server-side, capped at the same size limit as inline audio, and identified from the BYTES it returns rather than from its Content-Type, so an HTML error page served as 'audio/mpeg' is refused (unsupported_format) instead of being transcribed and charged to you. A URL must be publicly reachable: private, loopback and cloud-metadata addresses are refused (invalid_url). An oversized file is a 400 (audio_too_large) and is never billed. If the audio was the ONLY content in the message and it could not be retrieved, the request is refused (media_unavailable) rather than answered with an empty prompt you would still be billed for. BILLING IS IDENTICAL ACROSS THE THREE FORMS — a linked clip costs exactly what the same clip costs inline. You can also skip this part entirely: a user message whose WHOLE content is one audio link is promoted to exactly this part for you (see `messages[].content`); a promoted link that cannot be retrieved is left as ordinary text instead of being refused.",
    "format": "string - Audio format: 'wav' | 'mp3' | 'm4a' | 'flac' | 'ogg'. REQUIRED with bare base64 (nothing else names the type). OPTIONAL with an http(s) URL or a data URL, which describe themselves — supply it anyway and it is still validated the same way."
  }
}

Supported formats: WAV, MP3, M4A, FLAC, OGG
Size limit: 25MB (configurable)

Video Content (URL, YouTube or Base64)

Video Content (URL, YouTube or Base64)
{
  "type": "'video_url'",
  "video_url": {
    "url": "string - FOUR ACCEPTED FORMS, detected automatically from the value: (1) an http(s) URL to the video file — downloaded server-side, capped, and identified from its BYTES; (2) a public YouTube link (youtube.com/watch, youtu.be, shorts, live, embed) — read by its address, nothing is downloaded; (3) a data URL (data:video/<format>;base64,<data>); (4) bare base64. Containers: mp4, mov, webm, mkv, 3gp, avi, mpeg, flv, wmv. Up to 50 MB per video and 4 videos per message, 50 MB for all of a message's videos together (configurable); up to the first 20 minutes of a video are read. EVERY MODEL TIER can answer about a video: the platform first turns it into a text record — summary, timestamped visual timeline with all on-screen text, and a verbatim transcript in the spoken language — that the tier you selected reads. BILLING: that record's cost is billed as INPUT tokens of the tier you selected, inside the same `usage.prompt_tokens` you already read — no separate line item. A video sent again in a LATER message of the same conversation is NOT parsed or billed again: earlier videos are read from the project's record cache (keep sending your full `messages` history as usual). Errors (400, never billed): invalid_video_url, invalid_url (private address), unsupported_format, video_too_large, too_many_videos, video_unavailable (an explicit link that could not be downloaded, or a YouTube link to a video that does not exist, was removed or is private — the message says which and how to fix it), video_content_rejected (content restrictions). 413 payload_too_large when the request is larger than the platform reads in one request — never billed, do not retry as is. 503 server_busy + Retry-After when too many large requests (over 8 MB — inline videos) are being processed at that moment — retry after the delay; nothing was read or billed. 503 video_processing_unavailable + Retry-After when video reading is momentarily unavailable — retry; nothing is billed. For a public YouTube video that still cannot be read, the same 503 says so: unlisted, age-restricted and members-only videos cannot be read. On a project with `web_search_enabled` = true you can also skip this part entirely: a user message whose WHOLE content is one link to a video file is promoted to exactly this part for you (see `messages[].content`); with it off (the default) such a link stays text."
  }
}
Video request (curl)
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer $AINVENTED_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ainvented-low",
    "messages": [{
      "role": "user",
      "content": [
        { "type": "text", "text": "What happens in this clip? Quote what is said." },
        { "type": "video_url", "video_url": { "url": "https://cdn.example.com/clips/demo.mp4" } }
      ]
    }]
  }'

# A public YouTube link works the same way (nothing is downloaded):
#   { "type": "video_url", "video_url": { "url": "https://youtu.be/<id>" } }
# Inline: { "type": "video_url", "video_url": { "url": "data:video/mp4;base64,AAAAIGZ0eXBpc29t..." } }

Supported containers: MP4, MOV, WebM, MKV, 3GP, AVI, MPEG, FLV, WMV — identified from the bytes, not the extension
Limits: 50MB per video, 4 videos per message and 50MB for all of a message's videos together (configurable); the first 20 minutes are read
Every tier: the video becomes a text record (summary, on-screen text, transcript) that the tier you chose reads — it never switches tiers
Billing: the record's cost is billed as input tokens of the tier you selected, inside usage.prompt_tokens; a video resent in a later message of the conversation is read from cache and not billed again
Errors: invalid_video_url, unsupported_format, video_too_large, too_many_videos, video_unavailable, video_content_rejected — 400s, never billed. payload_too_large is a 413 (the request is larger than the platform reads at once), never billed. video_processing_unavailable is a 503 with Retry-After: retry, nothing was billed.

URL or Base64 — one rule for both fields

image_url.url and input_audio.data each accept the same three forms, and the form is detected from the value you send — there is no extra parameter to set. Base64 can never begin http:// or data:, so the detection is exact.

URL or Base64 — one rule for both fields
{
  "model": "ainvented-lite",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "Describe the picture, then transcribe the audio." },

        // (1) http(s) URL — downloaded server-side, capped, identified by its bytes
        { "type": "image_url", "image_url": { "url": "https://example.com/photo.jpg" } },

        // (2) data URL — the classic inline form
        { "type": "image_url", "image_url": { "url": "data:image/png;base64,iVBORw0KGgo..." } },

        // (3) bare base64 — no prefix, type read from the bytes
        { "type": "image_url", "image_url": { "url": "iVBORw0KGgo..." } },

        // Audio takes the same three forms in input_audio.data.
        // "format" is OPTIONAL here: the downloaded bytes name the type.
        { "type": "input_audio", "input_audio": { "data": "https://example.com/note.mp3" } },

        // "format" is REQUIRED with bare base64 — nothing else names the type.
        { "type": "input_audio", "input_audio": { "data": "UklGRiQ...", "format": "wav" } }
      ]
    }
  ]
}

Billing is identical across the three forms. A linked image or clip costs exactly what the same file costs inline — a URL is not a discount.
A URL is read as bytes, not as a header. A correct file served as application/octet-stream works; an HTML error page served as audio/mpeg is refused with unsupported_format instead of being transcribed and billed.
format is required only for bare base64. A URL and a data URL describe themselves; send it anyway and it is validated the same way.
URLs must be publicly reachable. Private, loopback and cloud-metadata addresses are refused with invalid_url.
Errors: invalid_image_url, invalid_url, unsupported_format, image_too_large, audio_too_large, media_unavailable — all 400s, none of them billed. A URL that is merely unreachable is skipped and the rest of the message is answered as usual.

A message that is only a link

You do not have to build a content part at all. When the entire content of the last user message is a single http(s) link whose path ends in an accepted media extension, it is treated as that file: downloaded, size-capped, identified from its bytes, and attached exactly as if you had written out the image_url / input_audio part yourself. This is what a chat widget, a WhatsApp relay or a bot usually sends when a person shares a photo or a voice note.

A message that is only a link
# The whole message is the link — no content parts to build.
curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ainvented-lite",
    "messages": [{ "role": "user", "content": "https://example.com/photo.jpg" }]
  }'

# Identical to sending it the long way:
#   "content": [
#     { "type": "image_url",
#       "image_url": { "url": "https://example.com/photo.jpg" } }
#   ]

# A voice note works the same way:
#   "content": "https://example.com/nota.mp3"

# NOT promoted — the link has company, so it keeps its meaning:
#   "content": "mira esto https://example.com/photo.jpg"    <- text + URL reading
#   "content": "https://example.com/a.jpg https://example.com/b.jpg"
#   "content": "https://example.com/articulo"               <- no media extension

# A link that cannot be used is NOT an error. The message stays the text you
# sent and goes to the model as text, exactly as it does today:
#   "content": "https://example.com/borrado.jpg"   (404)
#   -> the model receives the string "https://example.com/borrado.jpg"
#   -> nothing is billed for the file that never arrived

One link and nothing else. A caption, a question, a second link, or any other content part in the same message and nothing changes — the text stays text, and the URL reading described under messages[].content applies as before.
Extensions, not guesses. Images: jpg, jpeg, png, gif, webp, bmp, tif, tiff, avif. Audio: wav, mp3, m4a, flac, ogg. Video: mp4, m4v, mov, webm, mkv, 3gp, avi, mpg, mpeg, flv, wmv. Query strings are ignored, so presigned links work. A link with no media extension — a YouTube page included — is left alone.
A promoted video is answered, never refused. If it downloads but cannot be read, the reply says the video could not be processed instead of failing the request.
A bad link is never an error — it is just text again. Unreachable, private, oversized, or simply not the media its extension claimed: the message stays exactly what you sent, the URL reaches the model as ordinary text, and the turn behaves precisely as it did before this feature existed — including the URL reading above when your project enables it. No image or audio tokens are charged for a file that never arrived. This is the one difference from writing the part out by hand, where a media-only turn whose media failed is refused with media_unavailable.
Billed identically. A promoted link costs exactly what the same file costs written out in full, and it is fetched once — it is never also sent to the URL reader.
Independent of web_search_enabled. A media link is an attachment, not a page to read.

Base64 Image Examples

Python - Image Analysis

Python
Python - Image Analysis
import requests
import base64

api_key = "your_api_key_here"
url = "https://ainvented.com/api/v1/chat/completions"

# Read and encode image
with open("image.jpg", "rb") as image_file:
    image_data = base64.b64encode(image_file.read()).decode('utf-8')

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

data = {
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "What's in this image?"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/jpeg;base64,{image_data}",
                        "detail": "high"
                    }
                }
            ]
        }
    ],
    "max_tokens": 300
}

response = requests.post(url, headers=headers, json=data)
result = response.json()
print(result["choices"][0]["message"]["content"])

TypeScript - Image Analysis

TypeScript
TypeScript - Image Analysis
const apiKey = "your_api_key_here";
const url = "https://ainvented.com/api/v1/chat/completions";

// Read and encode image (Node.js)
import fs from 'fs';
const imageBuffer = fs.readFileSync('image.jpg');
const imageBase64 = imageBuffer.toString('base64');

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${apiKey}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    messages: [
      {
        role: "user",
        content: [
          {
            type: "text",
            text: "What's in this image?"
          },
          {
            type: "image_url",
            image_url: {
              url: `data:image/jpeg;base64,${imageBase64}`,
              detail: "high"
            }
          }
        ]
      }
    ],
    max_tokens: 300
  })
});

const result = await response.json();
console.log(result.choices[0].message.content);

cURL - Image Analysis

Bash
cURL - Image Analysis
# Portable on macOS and GNU/Linux
IMAGE_BASE64=$(base64 < image.jpg | tr -d '\n')

curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"messages\": [
      {
        \"role\": \"user\",
        \"content\": [
          {
            \"type\": \"text\",
            \"text\": \"What's in this image?\"
          },
          {
            \"type\": \"image_url\",
            \"image_url\": {
              \"url\": \"data:image/jpeg;base64,$IMAGE_BASE64\",
              \"detail\": \"high\"
            }
          }
        ]
      }
    ],
    \"max_tokens\": 300
  }"

Base64 Audio Examples

Python - Audio Transcription

Python
Python - Audio Transcription
import requests
import base64

api_key = "your_api_key_here"
url = "https://ainvented.com/api/v1/chat/completions"

# Read and encode audio
with open("audio.wav", "rb") as audio_file:
    audio_data = base64.b64encode(audio_file.read()).decode('utf-8')

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

data = {
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Transcribe this audio"
                },
                {
                    "type": "input_audio",
                    "input_audio": {
                        "data": audio_data,
                        "format": "wav"
                    }
                }
            ]
        }
    ],
    "max_tokens": 500
}

response = requests.post(url, headers=headers, json=data)
result = response.json()
print(result["choices"][0]["message"]["content"])

TypeScript - Audio Transcription

TypeScript
TypeScript - Audio Transcription
const apiKey = "your_api_key_here";
const url = "https://ainvented.com/api/v1/chat/completions";

// Read and encode audio (Node.js)
import fs from 'fs';
const audioBuffer = fs.readFileSync('audio.wav');
const audioBase64 = audioBuffer.toString('base64');

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${apiKey}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    messages: [
      {
        role: "user",
        content: [
          {
            type: "text",
            text: "Transcribe this audio"
          },
          {
            type: "input_audio",
            input_audio: {
              data: audioBase64,
              format: "wav"
            }
          }
        ]
      }
    ],
    max_tokens: 500
  })
});

const result = await response.json();
console.log(result.choices[0].message.content);

cURL - Audio Transcription

Bash
cURL - Audio Transcription
# Portable on macOS and GNU/Linux
AUDIO_BASE64=$(base64 < audio.wav | tr -d '\n')

curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"messages\": [
      {
        \"role\": \"user\",
        \"content\": [
          {
            \"type\": \"text\",
            \"text\": \"Transcribe this audio\"
          },
          {
            \"type\": \"input_audio\",
            \"input_audio\": {
              \"data\": \"$AUDIO_BASE64\",
              \"format\": \"wav\"
            }
          }
        ]
      }
    ],
    \"max_tokens\": 500
  }"

Browser-Based File Upload

When working in the browser, use the FileReader API to convert files to base64:

JavaScript - Browser File Upload

JavaScript
JavaScript - Browser File Upload
// Browser example — read the file locally, then send it to YOUR server.
// Your server adds the Ainvented API key and forwards the request securely.
const url = "/api/my-agent";

// Handle file input from user
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', async (e) => {
  const file = e.target.files[0];
  
  // Read file as base64
  const reader = new FileReader();
  reader.onload = async () => {
    // Extract base64 data (remove data URL prefix)
    const base64Data = reader.result.split(',')[1];
    
    const response = await fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        messages: [
          {
            role: "user",
            content: [
              {
                type: "text",
                text: "What's in this image?"
              },
              {
                type: "image_url",
                image_url: {
                  url: `data:image/jpeg;base64,${base64Data}`,
                  detail: "high"
                }
              }
            ]
          }
        ],
        max_tokens: 300
      })
    });
    
    const result = await response.json();
    console.log(result.choices[0].message.content);
  };
  
  reader.readAsDataURL(file);
});

Security Warning: Never expose your API key in client-side code. Always proxy requests through your backend server to keep API keys secure.

Combined Image and Audio Example

You can send multiple types of content in a single request for rich multimodal interactions:

Python - Combined Image and Audio

Python
Python - Combined Image and Audio
import requests
import base64

api_key = "your_api_key_here"
url = "https://ainvented.com/api/v1/chat/completions"

# Read and encode image
with open("chart.png", "rb") as image_file:
    image_data = base64.b64encode(image_file.read()).decode('utf-8')

# Read and encode audio
with open("narration.mp3", "rb") as audio_file:
    audio_data = base64.b64encode(audio_file.read()).decode('utf-8')

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

data = {
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Analyze this chart and transcribe the audio narration"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/png;base64,{image_data}",
                        "detail": "high"
                    }
                },
                {
                    "type": "input_audio",
                    "input_audio": {
                        "data": audio_data,
                        "format": "mp3"
                    }
                }
            ]
        }
    ],
    "max_tokens": 1000
}

response = requests.post(url, headers=headers, json=data)
result = response.json()
print(result["choices"][0]["message"]["content"])

Validation and Error Handling

All multimodal content is validated before processing. The following validations are performed:

  • Base64 encoding: Data must contain only valid base64 characters (A-Z, a-z, 0-9, +, /, =)
  • Data URL format: Image data URLs must follow the format: data:image/<format>;base64,<data>
  • MIME type: Must be a supported image or audio format
  • Size limits: Content must not exceed configured size limits (20MB for images, 25MB for audio)
  • Required fields: All required fields must be present (e.g., 'data' and 'format' for audio)

Common Validation Errors

Invalid base64 encoding in image data

The base64 string contains invalid characters. Ensure proper encoding.

Malformed data URL: missing MIME type

Data URL must include MIME type: data:image/jpeg;base64,...

Image size (25.3MB) exceeds limit (20MB)

Reduce image size or compress before encoding.

Unsupported image format: svg+xml. Supported formats: jpeg, png, gif, webp, bmp, tiff, avif

Convert image to a supported format. This is a 400 — the request never reaches a model, so it is not billed and retrying the same image will not succeed.

Missing required field 'format' in input_audio

Audio content must include both 'data' and 'format' fields.

Token Estimation for Multimodal Content

Multimodal content consumes tokens based on content type and size:

Image Tokens

  • Low detail: Fixed 85 tokens per image
  • High detail: 85 + (number of 512px tiles × 170) tokens
  • Auto detail: Automatically determined based on image size

Audio Tokens

Estimated based on audio duration: approximately 2 tokens per second of audio. When duration cannot be determined, a conservative estimate is used based on file size.

Note: Token estimates are included in usage tracking and billing records. The response includes a breakdown of text, image, and audio tokens consumed.

Best Practices for Multimodal Content

  • Optimize file sizes: Compress images and audio before encoding to reduce token usage and improve response times
  • Use appropriate detail levels: Use 'low' detail for simple image recognition, 'high' for detailed analysis
  • Handle validation errors: Implement proper error handling for validation failures with retry logic
  • Monitor size limits: Stay well below size limits (80% threshold triggers warnings)
  • Mix content types: Combine text, images, audio and video in a single message for rich interactions
  • Backward compatibility: Standard HTTP/HTTPS image URLs continue to work alongside base64 data URLs
Build · 18 endpoints

Voice

Turn text into natural speech, design a voice from a description or clone one from a recording, and transcribe audio — in more than twenty languages, with catalog voices for English, Spanish, French, German, Italian, Portuguese, Russian, Korean, Japanese, Chinese and Hindi. Calls can run on their own or inside a voice project, which keeps a history you can play, download and list later.

In this section
  1. GuideOverview
  2. GuideLanguages and voices
  3. GuideCost & metering
  4. POSTCreate speech/api/v1/audio/speech
  5. POSTTranscribe/api/v1/audio/transcriptions
  6. GETList voices/api/v1/audio/voices
  7. GETRead a voice/api/v1/audio/voices/{id}
  8. GETHear a voice/api/v1/audio/voices/{id}/preview
  9. POSTDesign a voice/api/v1/audio/voices/design
  10. POSTClone a voice/api/v1/audio/voices/clone
  11. POSTRename a voice/api/v1/audio/voices/{id}
  12. DELETEDelete a voice/api/v1/audio/voices/{id}
  13. POSTCreate a voice project/api/v1/voice-projects
  14. GETList voice projects/api/v1/voice-projects
  15. GETRead a voice project/api/v1/voice-projects/{id}
  16. POSTUpdate a voice project/api/v1/voice-projects/{id}
  17. DELETEArchive a voice project/api/v1/voice-projects/{id}
  18. GETHistory/api/v1/voice-projects/{id}/generations
  19. GETRead a history entry/api/v1/voice-projects/{id}/generations/{generationId}
  20. DELETERemove a history entry/api/v1/voice-projects/{id}/generations/{generationId}
  21. GETDownload audio/api/v1/voice-projects/{id}/generations/{generationId}/audio

Overview

  • Models. Speech: ainvented-voice (standard — the most natural, follows style directions) and ainvented-voice-low (low cost). Transcription: ainvented-transcribe. Clients built for the common speech and transcription APIs work unchanged: their model and voice names are accepted and mapped to these.
  • Voices. A catalog voice by its id (olivia, james, lena, chloe, sofia, jiwoo…, see GET /api/v1/audio/voices), or one of your project's own voices by the id design or cloning returned. Without voice, the text is read by the catalog voice of its own language. Any voice can speak any supported language; set language when the text is not in the voice's own language.
  • Voice projects. Pass voice_project_id on speech, design or transcription to keep the result in that project's history. Without it the call is billed the same and nothing is kept.
  • Keys. A project-scoped key works on its own project; an Admin key picks the project with project_id (or its first project), exactly as chat completions does.
cURL — speak a sentence
curl https://ainvented.com/api/v1/audio/speech \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"model":"ainvented-voice","voice":"olivia","input":"Hi, thanks for calling.","response_format":"mp3"}' \
  --output hello.mp3

Languages and voices

The catalog has a female and a male voice for English, Spanish, French, German, Italian, Portuguese, Russian, Korean, Japanese, Chinese and Hindi. Voices that name a region are built from a native speaker of it and keep that regional accent (native_accent: true in the voice list): British English, and Spanish from Mexico, Colombia, Argentina, Chile, Venezuela, the Caribbean and Spain. Speech can be generated in Arabic, Chinese, Danish, Dutch, English, Finnish, French, German, Greek, Hebrew, Hindi, Italian, Japanese, Korean, Malay, Norwegian, Polish, Portuguese, Russian, Spanish, Swahili, Swedish and Turkish; transcription recognizes about a hundred languages and detects the language by itself.

  • Any voice reads any language. Without language, the text is read in the language it is written in (an English sentence for a Spanish voice comes out as English, in that voice); when that is not clear — a single word, say — in the voice's own language. Send language to decide it yourself.
  • Another language stays clear. A native-accent, cloned or low-cost catalog voice reading a language other than its own is rendered with ainvented-voice on either model, because its accent would otherwise blur the words; it is billed as ainvented-voice and the X-Ainvented-Model header says so.
  • Native-accent voices and voices you cloned have one rendering, the one that keeps the speaker's accent and sounds most like them: both models give the same audio, billed as ainvented-voice-low (the X-Ainvented-Model header says so), and instructions are not applied to them (X-Ainvented-Instructions-Applied: false). Designed voices follow instructions on ainvented-voice.

Cost & metering

Speech and voice design are billed per character of text, transcription per second of audio (rounded up), cloning a voice is free (a clone sent without its language has it recognized from the recording, and those few seconds are billed), and catalog samples are free. Each call is charged once, to your project's budget when it has one or to your balance otherwise, and appears in consumption as component voice. A call refused by a budget, quota or balance check costs nothing, and a call that fails costs nothing. Every response reports what it consumed: speech in the X-Ainvented-Usage-Tokens header, the others in usage. These are billing tokens — the call's price expressed in tokens of your standard chat rate, the unit a project's token quota counts — not words or characters, so a short sentence can show a few thousand.

POST/api/v1/audio/speech#

Create speech

Speak `input` and answer the audio file itself (Content-Type per response_format). Billed per character.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "input": "string",
  "model": "string",
  "voice": "string",
  "response_format": "string",
  "speed": "number",
  "instructions": "string",
  "language": "string",
  "voice_project_id": "string",
  "project_id": "uuid"
}
Fields9Expand
input
stringrequired
≤4096 characters — the text to speak
model
stringoptional
'ainvented-voice' (default) or 'ainvented-voice-low'
voice
stringoptional
a catalog voice id or one of your voice ids; default: the voice project’s default, else the catalog voice of the text’s language (olivia for English, lena for German, elena for Spanish…; the English one when the language has no voice)
response_format
stringoptional
'mp3' (default), 'opus', 'aac', 'flac', 'wav' or 'pcm'
speed
numberoptional
0.25 to 4.0, default 1.0
instructions
stringoptional
≤500 — style direction (“warm and reassuring”); standard model only, not for native-accent or cloned voices
language
stringoptional
ISO code of the TEXT ('en', 'en-GB', 'fr', 'de', 'es-MX'…) or 'auto'; default: the language the text is written in when that is clear, else the voice’s
voice_project_id
stringoptional
keep the result in this voice project’s history
project_id
uuidoptional
Admin keys: the project to bill

Response Schema

JSON type shapeExpand
{
  "body": "the audio bytes",
  "X-Request-Id": "header",
  "X-Ainvented-Model": "header",
  "X-Ainvented-Characters": "header",
  "X-Ainvented-Usage-Tokens": "header",
  "X-Ainvented-Speed-Applied": "header",
  "X-Ainvented-Instructions-Applied": "header",
  "X-Ainvented-Generation-Id": "header",
  "X-Ainvented-Voice": "header"
}
Fields9Expand
body
the audio bytes
X-Request-Id
header
the request id
X-Ainvented-Model
header
the model billed
X-Ainvented-Characters
header
characters billed
X-Ainvented-Usage-Tokens
header
usage booked for the call
X-Ainvented-Speed-Applied
header
'true' | 'false'
X-Ainvented-Instructions-Applied
header
'true' | 'false' (some voices speak only in their own style)
X-Ainvented-Generation-Id
header
the history entry (only with voice_project_id)
X-Ainvented-Voice
header
the voice that read it (the catalog voice of the text’s language when no voice was sent)

Code Examples

curl https://ainvented.com/api/v1/audio/speech \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"input":"Your order has shipped.","voice":"olivia","response_format":"wav","speed":1.15,"instructions":"cheerful"}' \
  --output order.wav

Any client of the common speech API also works: point its base URL at https://ainvented.com/api/v1.

import { writeFile } from 'node:fs/promises'
const res = await fetch('https://ainvented.com/api/v1/audio/speech', {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.API_KEY}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({ model: 'ainvented-voice', voice: 'lena', input: 'Guten Morgen und herzlich willkommen.' }),
})
if (!res.ok) throw new Error(await res.text())
await writeFile('guten-morgen.mp3', Buffer.from(await res.arrayBuffer()))

Details

Errors

  • 400 invalid_model, invalid_input, input_too_long, invalid_language, invalid_speed, invalid_response_format — nothing was billed.
  • 404 voice_not_found — the voice id is not in the catalog nor one of this project's voices.
  • 402 budget_exhausted, token_limit_exhausted, insufficient_balance — refused before any work.
  • 409 voice_project_archived — the voice project no longer accepts work.
  • 503 voice_unavailable / 504 voice_timeout — retry; a failed call is not billed.
POST/api/v1/audio/transcriptions#

Create a transcription

Transcribe an audio file (multipart). Billed per second of audio. The recording is not stored.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "file": "binary",
  "model": "string",
  "language": "string",
  "prompt": "string",
  "response_format": "string",
  "timestamp_granularities[]": "string",
  "voice_project_id": "string",
  "project_id": "uuid"
}
Fields8Expand
file
binaryrequired
mp3, wav, m4a, ogg, webm or flac, up to 25 MB
model
stringoptional
'ainvented-transcribe'
language
stringoptional
ISO code hint ('es', 'en'…); omitted = detected
prompt
stringoptional
≤1000 — names and terms to spell right
response_format
stringoptional
'json' (default), 'text', 'srt', 'vtt' or 'verbose_json'
timestamp_granularities[]
stringoptional
repeatable — 'segment' and/or 'word' ('word' needs verbose_json)
voice_project_id
stringoptional
keep the transcript in this voice project’s history
project_id
uuidoptional
Admin keys: the project to bill

Response Schema

JSON type shapeExpand
{
  "text": "string",
  "language": "string (verbose_json)",
  "duration": "number (verbose_json)",
  "segments": "[{ id, start, end, text }] (verbose_json)",
  "words": "[{ word, start, end }] (verbose_json with word granularity)",
  "usage": "{ type: \"duration\", seconds, total_tokens } (json forms)"
}
Fields6Expand
text
string
the transcript
language
string (verbose_json)
the detected or given language
duration
number (verbose_json)
seconds
segments
[{ id, start, end, text }] (verbose_json)
words
[{ word, start, end }] (verbose_json with word granularity)
usage
{ type: "duration", seconds, total_tokens } (json forms)

Code Examples

curl https://ainvented.com/api/v1/audio/transcriptions \
  -H "Authorization: Bearer $API_KEY" \
  -F file=@interview.mp3 -F response_format=srt
# The language is detected; add -F language=de to set it.
GET/api/v1/audio/voices#

List voices

The catalog plus your project's own voices. Filter with ?language=en (or en-GB), ?source=catalog|custom. Free.

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "object": "'list'",
  "data": "[{ id, object: 'voice', name, description, language, locale (catalog), gender (catalog), style (catalog), source: 'catalog'|'clone'|'design', tiers, preview_available, native_accent (catalog: built from a native speaker, keeps its regional accent) }]",
  "languages": "string[]",
  "project_id": "uuid"
}
Fields4Expand
object
'list'
data
[{ id, object: 'voice', name, description, language, locale (catalog), gender (catalog), style (catalog), source: 'catalog'|'clone'|'design', tiers, preview_available, native_accent (catalog: built from a native speaker, keeps its regional accent) }]
languages
string[]
languages speech can be generated in
project_id
uuid
the project whose voices are listed

Code Examples

curl "https://ainvented.com/api/v1/audio/voices?language=en" -H "Authorization: Bearer $API_KEY"
GET/api/v1/audio/voices/{id}#

Read a voice

One catalog voice by id, or one of your voices. POST to the same path renames or describes one of your voices ({ name?, description? }); DELETE removes it.

Authentication

Bearer <api_key>

GET/api/v1/audio/voices/{id}/preview#

Hear a catalog voice

A short sample of a catalog voice (audio bytes). Free.

Authentication

Bearer <api_key>

POST/api/v1/audio/voices/design#

Design a voice

A voice from a written description. Answers a billed sample; with save: true the voice is kept and its id works as `voice` in speech.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "description": "string",
  "language": "string",
  "text": "string",
  "save": "boolean",
  "name": "string",
  "voice_project_id": "string",
  "project_id": "uuid"
}
Fields7Expand
description
stringrequired
10–1000 — who is speaking: age, gender, tone, accent
language
stringoptional
the sample's language, default 'en'
text
stringoptional
≤1000 — the sentence the sample reads
save
booleanoptional
keep the voice
name
stringoptional
≤120 — its name when kept
voice_project_id
stringoptional
project_id
uuidoptional

Response Schema

JSON type shapeExpand
{
  "voice": "Voice | null",
  "saved": "boolean",
  "save_error": "{ code, message }",
  "audio": "{ data: base64, format, mime_type }",
  "characters": "number",
  "usage": "object",
  "generation_id": "string | null"
}
Fields7Expand
voice
Voice | null
the kept voice
saved
boolean
save_error
{ code, message }optional
only when saving failed; the sample is still returned and billed
audio
{ data: base64, format, mime_type }
characters
number
usage
object
generation_id
string | null

Code Examples

curl https://ainvented.com/api/v1/audio/voices/design \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"description":"A woman in her thirties, warm and clear, calm and reassuring","language":"en","save":true,"name":"Claire"}'
# For an authentic regional accent, use a catalog voice from that country (native_accent: true)
# or clone a native speaker: an accent written in the description is only approximate.
POST/api/v1/audio/voices/clone#

Clone a voice

Keep a recorded voice as one of your project's voices (multipart). Free when you name the language it speaks. You must have the speaker's permission; delete it at any time.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "file": "binary",
  "name": "string",
  "consent": "'true'",
  "description": "string",
  "language": "string",
  "voice_project_id": "string",
  "project_id": "uuid"
}
Fields7Expand
file
binaryrequired
5–30 s of one person speaking clearly, up to 10 MB
name
stringrequired
≤120
consent
'true'required
you confirm the speaker's permission
description
stringoptional
≤1000
language
stringoptional
the language the recording speaks (ISO 639-1). It decides how the voice reads every other language. Omitted or 'auto': recognized from the recording, and those few seconds are billed
voice_project_id
stringoptional
project_id
uuidoptional

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'voice'",
  "name": "string",
  "source": "'clone'",
  "language": "string | null",
  "created_at": "ISO"
}
Fields6Expand
id
string
use as `voice`
object
'voice'
name
string
source
'clone'
language
string | null
created_at
ISO

Code Examples

curl https://ainvented.com/api/v1/audio/voices/clone \
  -H "Authorization: Bearer $API_KEY" \
  -F file=@sam.mp3 -F name="Sam" -F language=en -F consent=true
# Leave language out to have it recognized from the recording (those few seconds are billed).
POST/api/v1/audio/voices/{id}#

Rename a voice

Rename or describe one of your voices. Catalog voices are read-only (400 voice_read_only).

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "description": "string | null"
}
Fields2Expand
name
stringoptional
≤120
description
string | nulloptional
≤1000
DELETE/api/v1/audio/voices/{id}#

Delete a voice

Deletes one of your voices and its recording. Audio already generated with it stays in your history.

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'voice'",
  "deleted": "true"
}
Fields3Expand
id
string
object
'voice'
deleted
true
POST/api/v1/voice-projects#

Create a voice project

A workspace with its own history and defaults. Free.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "description": "string",
  "default_voice": "string",
  "default_model": "'ainvented-voice' | 'ainvented-voice-low'",
  "default_language": "string",
  "default_format": "'mp3'|'opus'|'aac'|'flac'|'wav'|'pcm'",
  "project_id": "uuid"
}
Fields7Expand
name
stringrequired
1–120
description
stringoptional
≤1000
default_voice
stringoptional
default_model
'ainvented-voice' | 'ainvented-voice-low'optional
default_language
stringoptional
default_format
'mp3'|'opus'|'aac'|'flac'|'wav'|'pcm'optional
project_id
uuidoptional
Admin keys

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'voice_project'",
  "name": "string",
  "description": "string|null",
  "project_id": "uuid",
  "status": "'active'|'archived'",
  "default_voice": "string|null",
  "default_model": "string|null",
  "default_language": "string|null",
  "default_format": "string|null",
  "generation_count": "number",
  "created_at": "ISO",
  "updated_at": "ISO"
}
Fields13Expand
id
string
object
'voice_project'
name
string
description
string|null
project_id
uuid
status
'active'|'archived'
default_voice
string|null
default_model
string|null
default_language
string|null
default_format
string|null
generation_count
number
created_at
ISO
updated_at
ISO

Code Examples

curl https://ainvented.com/api/v1/voice-projects \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"name":"Support line","default_voice":"olivia","default_language":"en"}'
GET/api/v1/voice-projects#

List voice projects

?status=active (default)|archived|all, ?limit (≤100), ?cursor, ?order=asc|desc.

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "object": "'list'",
  "data": "VoiceProject[]",
  "next_cursor": "string | null"
}
Fields3Expand
object
'list'
data
VoiceProject[]
next_cursor
string | null
GET/api/v1/voice-projects/{id}#

Read a voice project

One voice project, with its generation_count.

Authentication

Bearer <api_key>

POST/api/v1/voice-projects/{id}#

Update a voice project

Rename, describe or change its defaults (send null to clear a default). 409 when archived.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "description": "string|null",
  "default_voice": "string|null",
  "default_model": "string|null",
  "default_language": "string|null",
  "default_format": "string|null"
}
Fields6Expand
name
stringoptional
description
string|nulloptional
default_voice
string|null
default_model
string|null
default_language
string|null
default_format
string|null
DELETE/api/v1/voice-projects/{id}#

Archive a voice project

Stops new work in it; the history stays readable. Idempotent.

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'voice_project'",
  "status": "'archived'",
  "deleted": "true"
}
Fields4Expand
id
string
object
'voice_project'
status
'archived'
deleted
true
GET/api/v1/voice-projects/{id}/generations#

List a voice project's history

Newest first. ?kind=speech|design|transcription, ?limit, ?cursor.

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "object": "'list'",
  "data": "[{ id, object: 'voice_generation', kind, input, transcript, voice, model, language, format, units, unit: 'character'|'second', cost_micros, duration_ms, has_audio, audio_url, details, created_at }]",
  "next_cursor": "string | null"
}
Fields3Expand
object
'list'
data
[{ id, object: 'voice_generation', kind, input, transcript, voice, model, language, format, units, unit: 'character'|'second', cost_micros, duration_ms, has_audio, audio_url, details, created_at }]
next_cursor
string | null
GET/api/v1/voice-projects/{id}/generations/{generationId}#

Read a history entry

One entry, including transcript segments. DELETE on the same path removes it and its stored audio (the charge stays on your ledger).

Authentication

Bearer <api_key>

DELETE/api/v1/voice-projects/{id}/generations/{generationId}#

Remove a history entry

Removes the entry and its stored audio.

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'voice_generation'",
  "deleted": "true"
}
Fields3Expand
id
string
object
'voice_generation'
deleted
true
GET/api/v1/voice-projects/{id}/generations/{generationId}/audio#

Download generated audio

The stored audio of a speech or design entry, as an attachment named for what it is (project, voice and the first words: anuncio-verano-sofia-este-verano-refrescate.mp3). Free (it was billed when generated).

Authentication

Bearer <api_key>

Build · 9 endpoints

Decisions

Ask typed questions about any text or JSON — a ticket, a message, a form, a product record — and get back answers with calibrated probabilities in a fraction of a second: yes / no, a choice between your options, or a score on your own levels. Many questions are answered in one call. Calls can run on their own or inside a decision project, which keeps a saved question set and a history of its runs.

In this section
  1. GuideOverview
  2. GuideQuestion types
  3. GuideActing on the answers
  4. GuideCost & metering
  5. POSTMake a decision/api/v1/decisions
  6. POSTCreate a decision project/api/v1/decision-projects
  7. GETList decision projects/api/v1/decision-projects
  8. GETRead a decision project/api/v1/decision-projects/{id}
  9. POSTUpdate a decision project/api/v1/decision-projects/{id}
  10. DELETEArchive a decision project/api/v1/decision-projects/{id}
  11. GETHistory/api/v1/decision-projects/{id}/runs
  12. GETRead a run/api/v1/decision-projects/{id}/runs/{runId}
  13. DELETERemove a run/api/v1/decision-projects/{id}/runs/{runId}

Overview

  • Model. ainvented-verdict — built for classification and decisions, not for writing text: it returns probabilities, never prose. It is not a chat model: /v1/chat/completions refuses it (400 unsupported_model, free). The ainvented- prefix is optional, as for the chat tiers: verdict works too, and every answer names ainvented-verdict. model may be omitted.
  • Two ways to ask. Send questions with every call, or save them once in a decision project and send only input with its decision_project_id (the run is then kept in that project's history). questions on the call wins over the saved set.
  • Input. A string, or any JSON object or array (it is read as structured data). Up to about 64,000 tokens with the questions.
  • Keys. A project-scoped key works on its own project; an Admin key picks the project with project_id (or its first project), exactly as chat completions does.
cURL — three questions about one message
curl https://ainvented.com/api/v1/decisions \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{
    "model": "ainvented-verdict",
    "input": "Hi, I was charged twice this month and I need a refund today.",
    "questions": {
      "refund":  {"type": "yes_no", "instructions": "Does the customer ask for a refund?"},
      "team":    {"type": "choice", "instructions": "Which team should handle it?", "options": ["billing", "technical", "sales", "account"]},
      "urgency": {"type": "score",  "instructions": "How urgent is it?", "levels": ["Can wait", "This week", "Today", "Right now"]}
    }
  }'
Response
{
  "id": "8d0f1c9e-…",
  "object": "decision",
  "created": 1760467200,
  "model": "ainvented-verdict",
  "answers": {
    "refund":  { "type": "yes_no", "answer": true, "probability": 0.97 },
    "team":    { "type": "choice", "choice": "billing", "confidence": 0.93,
                 "probabilities": { "billing": 0.95, "account": 0.03, "technical": 0.01, "sales": 0.01 } },
    "urgency": { "type": "score", "score": 2.31, "confidence": 0.82,
                 "levels": { "0": "Can wait", "1": "This week", "2": "Today", "3": "Right now" },
                 "probabilities": { "0": 0.02, "1": 0.09, "2": 0.45, "3": 0.44 } }
  },
  "usage": { "input_tokens": 118, "output_tokens": 41, "total_tokens": 159 }
}

Question types

questions is an object: each key is the id the answer comes back under (letters, digits and _ . : -, up to 64 characters), each value one question. instructions, option descriptions and levels may be text or a JSON object / array. Up to 256 questions per call.

  • yes_no — { "type": "yes_no", "instructions": "…", "criteria"?: { "yes"?: "…", "no"?: "…" } }. Answer: answer (true when probability ≥ 0.5) and probability of yes.
  • choice — { "type": "choice", "instructions": "…", "options": ["a", "b"] }, or options with descriptions { "a": "when…", "b": null }; 2 to 255 options, names up to 200 characters. Answer: choice, confidence and the probabilities of every option.
  • score — { "type": "score", "instructions": "…", "levels": ["lowest", …, "highest"] }; 2 to 10 levels, lowest first. Answer: score (a number from 0 to the last level's index), confidence, the levels by index and their probabilities.

A question the model could not answer comes back as null, never as a guess. Write each condition exactly: the model reads it literally.

  • Point at one part of a JSON input by its path, in backticks: "Does `ticket.messages[0].text` ask for a refund?" judges that message only.
  • Ask every question about one input in the same call. They are answered together; each extra question adds only its own tokens to the cost and barely any time. Answers come back in the order you asked.
  • Answers are independent: one answer is never context for another. When a question really depends on an earlier answer, make a second call with it.

Acting on the answers

Every answer is a number your code can compare: act on choice when confidence is high, ask a person when it is not, and raise the bar for actions that are hard to undo. A yes_noanswer has no separate confidence: its probability near 1 or 0 is sure, near 0.5 is not.

Python — route a message, escalate when unsure
import os
import requests

BASE = "https://ainvented.com"
KEY = os.environ["API_KEY"]

def decide(message):
    r = requests.post(
        f"{BASE}/api/v1/decisions",
        headers={"Authorization": f"Bearer {KEY}"},
        json={
            "input": message,
            "questions": {
                "action": {"type": "choice", "instructions": "What does the customer want to do?",
                           "options": {"check_balance": "See their balance",
                                       "close_account": "Close their account",
                                       "support": "Get help with a problem"}},
                "angry": {"type": "yes_no", "instructions": "Is the customer angry?"},
            },
        },
        timeout=30,
    )
    body = r.json()
    if not r.ok:  # a 400 says what to fix and costs nothing
        raise SystemExit(f"{body['error']['code']}: {body['error']['message']}")
    return body["answers"]

answers = decide("Please close my account today, I am moving to another bank.")
action, angry = answers["action"], answers["angry"]

if action is None or action["confidence"] < 0.5:
    print("unsure: send it to a person")
elif action["choice"] == "close_account":
    # hard to undo: act alone only when very sure
    print("close it" if action["confidence"] > 0.9 else "ask the customer to confirm")
else:
    print("handle:", action["choice"])
if angry is not None and angry["probability"] > 0.8:
    print("and flag it for a senior agent")

Start with conservative thresholds, check them against your own data, then adjust.

Cost & metering

Decisions are billed per input token (the input plus the questions); output tokens are reported in usage but not charged. Each call is charged once, to your project's budget when it has one or to your balance otherwise, and appears in consumption as component decision. A call refused by a budget, quota or balance check costs nothing, a malformed request costs nothing, and a call that fails costs nothing. usagereports the tokens billed for the call: the per-token price on the pricing pagetimes usage.input_tokens is what it costs.

A decision usually answers in well under a second. Under exceptionally heavy load it is still answered rather than refused — in the same shape, in a few seconds — and may then be billed more tokens than usual; usage always says how many. Give your client a timeout of at least 15 seconds.

POST/api/v1/decisions#

Make a decision

Answer every question about one input, with probabilities. Billed per input token; refusals and failures cost nothing.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "input": "string | object | array",
  "questions": "object",
  "model": "string",
  "decision_project_id": "string",
  "project_id": "uuid"
}
Fields5Expand
input
string | object | arrayrequired
the text or JSON to decide about
questions
objectrequired
unless decision_project_id has saved questions — { "<id>": { type, instructions, … } }, see Question types
model
stringoptional
'ainvented-verdict', or 'verdict' (the prefix is optional)
decision_project_id
stringoptional
run in this decision project: its saved questions apply when `questions` is omitted, and the run is kept in its history
project_id
uuidoptional
Admin keys: the project to bill

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'decision'",
  "created": "number",
  "model": "'ainvented-verdict'",
  "answers": "{ \"<id>\": YesNoAnswer | ChoiceAnswer | ScoreAnswer | null }",
  "usage": "{ input_tokens, output_tokens, total_tokens }",
  "decision_project_id": "string (only with decision_project_id)",
  "run_id": "string | null (only with decision_project_id)"
}
Fields8Expand
id
string
the request id (also in the X-Request-Id header)
object
'decision'
created
number
unix seconds
model
'ainvented-verdict'
answers
{ "<id>": YesNoAnswer | ChoiceAnswer | ScoreAnswer | null }
usage
{ input_tokens, output_tokens, total_tokens }
decision_project_id
string (only with decision_project_id)
run_id
string | null (only with decision_project_id)
the history entry

Code Examples

curl https://ainvented.com/api/v1/decisions \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"decision_project_id":"cmg1abcde0000xyz12345678","input":{"subject":"Invoice 4411","body":"Charged twice, please refund."}}'
// node review.mjs   (API_KEY in the environment)
const res = await fetch('https://ainvented.com/api/v1/decisions', {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.API_KEY}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    input: 'Setup took two minutes and the battery lasts all week. Love it.',
    questions: { positive: { type: 'yes_no', instructions: 'Is the review positive overall?' } },
  }),
})
const body = await res.json()
if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`)
const { answer, probability } = body.answers.positive
console.log(answer, probability) // true 0.98

Details

Errors

  • 400 invalid_input, invalid_question, too_many_questions, input_too_long, questions_required, project_mismatch — param names the field and the message says what to change (a questions list, for instance, is answered with the object form it takes); nothing was billed.
  • 400 project_missing — an Admin key on an account with no project yet: create one (dashboard, or POST /api/v1/projects) and retry.
  • 404 decision_project_not_found — the decision project does not exist, is not yours, or is outside the key's project.
  • 402 budget_exhausted, token_limit_exhausted, insufficient_balance — refused before any work. A project created with POST /api/v1/projects without budget_cents has no budget yet: the message says so — set one with PUT /api/v1/projects/{id} and retry.
  • 409 decision_project_archived — the decision project no longer accepts work.
  • 429 — too many requests, or the service is at capacity (Retry-After says when to retry).
  • 503 decision_busy, 503 decision_unavailable, 504 decision_timeout — the call could not be answered at all: retry shortly; a failed call is not billed. Under heavy load or a passing incident the service keeps answering, in the same shape, so these are rare.
POST/api/v1/decision-projects#

Create a decision project

A workspace with a saved question set and a history. Free. 409 duplicate_name when an active one already has the name — the message gives its id, so a script that runs twice can use it.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "description": "string",
  "questions": "object",
  "template": "string",
  "project_id": "uuid"
}
Fields5Expand
name
stringrequired
1–120
description
stringoptional
≤1000
questions
objectoptional
the saved question set
template
stringoptional
start from 'support_triage', 'lead_qualification' or 'content_safety' (ignored when questions is sent)
project_id
uuidoptional
Admin keys

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'decision_project'",
  "name": "string",
  "description": "string|null",
  "project_id": "uuid",
  "status": "'active'|'archived'",
  "model": "'ainvented-verdict'",
  "questions": "object|null",
  "question_count": "number",
  "run_count": "number",
  "created_at": "ISO",
  "updated_at": "ISO"
}
Fields12Expand
id
string
object
'decision_project'
name
string
description
string|null
project_id
uuid
status
'active'|'archived'
model
'ainvented-verdict'
questions
object|null
question_count
number
run_count
number
runs in its history (create, read, list)
created_at
ISO
updated_at
ISO

Code Examples

curl https://ainvented.com/api/v1/decision-projects \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"name":"Support triage","template":"support_triage"}'
GET/api/v1/decision-projects#

List decision projects

?status=active (default)|archived|all, ?limit (≤100), ?cursor, ?order=asc|desc.

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "object": "'list'",
  "data": "DecisionProject[]",
  "next_cursor": "string | null"
}
Fields3Expand
object
'list'
data
DecisionProject[]
next_cursor
string | null
GET/api/v1/decision-projects/{id}#

Read a decision project

One decision project, with its questions and run_count.

Authentication

Bearer <api_key>

POST/api/v1/decision-projects/{id}#

Update a decision project

Rename, describe or replace its question set (send questions: null to clear it). PATCH on the same path does the same. 409 when archived.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "description": "string|null",
  "questions": "object|null"
}
Fields3Expand
name
stringoptional
description
string|nulloptional
questions
object|nulloptional
DELETE/api/v1/decision-projects/{id}#

Archive a decision project

Stops new decisions in it; the history stays readable. Idempotent.

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'decision_project'",
  "status": "'archived'",
  "deleted": "true"
}
Fields4Expand
id
string
object
'decision_project'
status
'archived'
deleted
true
GET/api/v1/decision-projects/{id}/runs#

List a decision project's history

Newest first. ?limit (≤100), ?cursor.

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "object": "'list'",
  "data": "[{ id, object: 'decision_run', decision_project_id, model, input (null when it was longer than 50,000 characters), input_preview, input_truncated, questions, answers, usage, cost_micros, source: 'api'|'workspace', created_at }]",
  "next_cursor": "string | null"
}
Fields3Expand
object
'list'
data
[{ id, object: 'decision_run', decision_project_id, model, input (null when it was longer than 50,000 characters), input_preview, input_truncated, questions, answers, usage, cost_micros, source: 'api'|'workspace', created_at }]
next_cursor
string | null
GET/api/v1/decision-projects/{id}/runs/{runId}#

Read a run

One run: its input, the questions it was asked and the answers.

Authentication

Bearer <api_key>

DELETE/api/v1/decision-projects/{id}/runs/{runId}#

Remove a run

Removes the run from the history (what it cost stays on your ledger).

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'decision_run'",
  "deleted": "true"
}
Fields3Expand
id
string
object
'decision_run'
deleted
true
POST/api/v1/workflows/execute#

Execute Workflow

Execute a workflow project programmatically with custom input parameters. The workflow runs using the same logic as the UI, returning results formatted with node labels as keys.

Authentication

Bearer token required in Authorization header. API key must be scoped to a workflow project.

Request Schema

JSON type shapeExpand
{
  "project_id": "string",
  "input_vars": "object",
  "images": "string[]",
  "audios": "string[]",
  "videos": "string[]",
  "urls": "string[]",
  "url_inputs": "array",
  "external_apis": "array",
  "model": "string",
  "reasoning_effort": "string"
}
Fields10Expand
project_id
stringoptional
Workflow project ID (ignored if API key is scoped to a project)
input_vars
objectoptional
Key-value pairs for workflow input variables
images
string[]optional
Array of base64-encoded image strings
audios
string[]optional
Array of base64-encoded audio strings
videos
string[]optional
Array of videos (data:video/<format>;base64,... or bare base64; up to 4 videos, 50 MB in total) for the nodes wired to a Video Input node. Each is read as a text record (summary, on-screen text, transcript) and billed as input tokens of the node's tier. A video LINK goes in `urls` / `url_inputs` instead — it is read the same way. Refused before anything runs or is billed: 400 invalid_type, invalid_value (a link), too_many_videos, invalid_base64 / empty_base64 (data that is not base64), video_too_large. A video the platform cannot read (not a video, or no video track) fails the run with 400 unsupported_media_type (413 payload_too_large; 503 video_processing_unavailable + Retry-After means retry) and is not billed.
urls
string[]optional
Array of URL strings the platform reads for the run. A link inside a private network (localhost, 10.x, 169.254.x, …) is refused with 400 invalid_url before anything runs; one whose name resolves there is not read.
url_inputs
arrayoptional
Array of URL input objects with nodeId, customLabel, urls, and enabled fields. Each url follows the `urls` rule: one inside a private network is refused with 400 invalid_url.
external_apis
arrayoptional
Array of external API configuration objects. Each url must be a public http(s) address: one that points inside a private network (localhost, 10.x, 169.254.x, …) is refused with 400 invalid_url before anything runs, and one whose name resolves there, or that redirects there, fails the run with 400 invalid_url.
model
stringoptional
Model tier for this run: 'ainvented-eon' / 'eon' (our most capable model) where GET /v1/models lists it, or 'ainvented-epic' | 'ainvented-saga' | 'ainvented-lite' | 'ainvented-low' (the bare words 'epic', 'saga', 'lite' and 'low' are accepted too). Acts as this run's WORKFLOW DEFAULT: it moves every node whose author left it on the default, and leaves explicitly pinned nodes on their pin — so one caller cannot silently downgrade the node a workflow was built around. Omit to use the workflow's own default, then the project's. An unrecognised value is a 400, never a silent downgrade.
reasoning_effort
stringoptional
How much the model reasons before answering: 'low' | 'medium' | 'high' | 'xhigh' | 'max'. Same precedence as `model`. Higher effort produces more reasoning tokens, which are billed as output tokens. Omit to use each node's tier default.

Response Schema

JSON type shapeExpand
{
  "success": "boolean",
  "output": "object",
  "execution_time_ms": "number"
}
Fields3Expand
success
boolean
Execution success status
output
object
Workflow output with node labels as keys
execution_time_ms
number
Execution duration in milliseconds

Code Examples

Basic workflow execution with input variables and URLs

curl https://ainvented.com/api/v1/workflows/execute \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input_vars": {
      "search_query": "AI news",
      "max_results": 10
    },
    "urls": ["https://example.com/feed"]
  }'

Execute workflow with error handling

import requests

api_key = "your_api_key_here"
url = "https://ainvented.com/api/v1/workflows/execute"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

data = {
    "input_vars": {
        "search_query": "AI news",
        "max_results": 10
    },
    "urls": ["https://example.com/feed"]
}

response = requests.post(url, headers=headers, json=data)
result = response.json()

if result["success"]:
    print("Workflow output:", result["output"])
    print(f"Execution time: {result['execution_time_ms']}ms")
else:
    print("Error:", result["error"])

Execute workflow using fetch API

const apiKey = "your_api_key_here";
const url = "https://ainvented.com/api/v1/workflows/execute";

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${apiKey}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    input_vars: {
      search_query: "AI news",
      max_results: 10
    },
    urls: ["https://example.com/feed"]
  })
});

const result = await response.json();

if (result.success) {
  console.log("Workflow output:", result.output);
  console.log(`Execution time: ${result.execution_time_ms}ms`);
} else {
  console.error("Error:", result.error);
}

Type-safe workflow execution

interface WorkflowRequest {
  input_vars?: Record<string, any>;
  images?: string[];
  audios?: string[];
  videos?: string[];
  urls?: string[];
  url_inputs?: Array<{
    nodeId: string;
    customLabel?: string;
    urls: string[];
    enabled: boolean;
  }>;
  external_apis?: Array<{
    nodeId?: string;
    name: string;
    url: string;
    method: string;
    headers: string;
    body: string;
  }>;
}

interface WorkflowResponse {
  success: boolean;
  output: Record<string, any>;
  execution_time_ms: number;
}

const apiKey = "your_api_key_here";
const url = "https://ainvented.com/api/v1/workflows/execute";

const request: WorkflowRequest = {
  input_vars: {
    search_query: "AI news",
    max_results: 10
  },
  urls: ["https://example.com/feed"]
};

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${apiKey}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify(request)
});

const result: WorkflowResponse = await response.json();

if (result.success) {
  console.log("Workflow output:", result.output);
  console.log(`Execution time: ${result.execution_time_ms}ms`);
}

Details

Input Parameters

Workflow input parameters match the format used in the UI's "Input Parameters" modal. All parameters are optional, but at least one should be provided:

  • input_vars: Object with key-value pairs for workflow variables
  • images: Array of base64-encoded image strings
  • audios: Array of base64-encoded audio strings
  • videos: Array of base64-encoded videos (or data:video/… URLs) for nodes wired to a Video Input node — each is read as a text record and billed as input tokens of the node's tier
  • urls: Array of URL strings for web scraping or data fetching (a link to a video file, or a public YouTube link, is read as a video)
  • url_inputs: Array of URL input objects with node-specific configuration
  • external_apis: Array of external API configuration objects — each url must be a public http(s) address; one inside a private network (or resolving or redirecting there) is refused with 400 invalid_url

Choosing a model

A workflow is not one kind of work. “Pull the invoice number out of this PDF” and “write the customer's reply” have different value and different cost, so each node in a workflow can run on its own model tier and its own reasoning effort, set in the functions‑workflow‑builder.

The optional model and reasoning_effort fields set the default for this run. They move every node whose author left it on the default and leave explicitly pinned nodes alone — so passing "model": "low"makes the cheap steps cheaper without quietly downgrading the one step the workflow exists for.

  • Precedence, highest first: the node's own pin → this request → the workflow default → the project default → ainvented-lite.
  • Accepted models, most capable first: ainvented-eon where GET /v1/models lists it, ainvented-epic, ainvented-saga, ainvented-lite and ainvented-low. The bare words eon, epic, saga, lite, low work too.
  • Accepted efforts: low, medium, high, xhigh, max. Reasoning tokens are billed as output tokens, so a higher effort costs more.
  • An unrecognised value returns 400. An empty string means “not selected” and is accepted.
  • A node that sends images keeps its tier: every tier reads images. Image requests on ainvented-saga are billed at the ainvented-epic rate; ainvented-eon always bills at its own rate.
  • GET /v1/models lists the tiers available to you.

Output Format

The workflow output is formatted with node labels as keys, matching the format displayed in the UI toaster. Each node's output is accessible by its label:

Workflows may include Files and Multimodal RAG context nodes (configured in the functions‑workflow‑builder). They enrich downstream nodes with file URLs or vector‑store search results and are billed to your project as audited usage. They are internal to the workflow and do not change this endpoint's request or response contract.

Output
{
  "success": true,
  "output": {
    "Web Scraper": {
      "articles": [
        {"title": "AI Breakthrough", "url": "..."},
        {"title": "ML Advances", "url": "..."}
      ]
    },
    "Summarizer": {
      "summary": "Recent AI developments include..."
    }
  },
  "execution_time_ms": 2341
}

Project Selection

The API determines which workflow project to execute based on this priority order:

  1. API key's associated project (if configured) - Takes precedence over all other options
  2. project_id parameter (if API key is not scoped to a project)
  3. Your default project (first created workflow project)

Note: For workflow execution, it's recommended to scope your API key to a specific workflow project. This ensures proper access control and prevents accidental execution of the wrong workflow.

Rate Limiting

Workflow execution uses the same rate limiting as the chat completions endpoint. Rate limit headers are included in all responses:

  • X-RateLimit-Limit: Maximum requests per time window
  • X-RateLimit-Remaining: Requests remaining in current window
  • X-RateLimit-Reset: Unix timestamp when limit resets

Error Responses

Workflow execution can return the following error codes:

Error Responses
{
  "error": {
    "message": "string - Human-readable error message",
    "type": "string - Error type (authentication_error, permission_denied, validation_error, etc.)",
    "code": "string - Specific error code"
  }
}
  • 401 Unauthorized: Invalid, missing, or revoked API key
  • 403 Forbidden: Project doesn't belong to your account or is disabled
  • 404 Not Found: Workflow project doesn't exist
  • 422 Validation Error: Invalid input parameters or malformed JSON
  • 429 Too Many Requests: Rate limit exceeded
  • 500 Server Error: Workflow execution failed or internal error

Example Success Response

Example Success Response
{
  "success": true,
  "output": {
    "Web Scraper": {
      "articles": [
        {"title": "AI Breakthrough", "url": "https://example.com/article1"},
        {"title": "ML Advances", "url": "https://example.com/article2"}
      ]
    },
    "Summarizer": {
      "summary": "Recent AI developments include breakthrough in neural networks..."
    }
  },
  "execution_time_ms": 2341
}

Example Error Response

Example Error Response
{
  "error": {
    "message": "Invalid API key. Please check your API key and try again.",
    "type": "invalid_request_error",
    "code": "authentication_error"
  }
}
Reference · 8 endpoints

Projects

Manage chat projects with their assigned API keys, two independent quotas (cents-budget and token-units quota), currency, alert thresholds, and hard-cap policies. Every monetized AI call routes through both quotas — when hard_cap is true and consumed >= budget, the gate refuses with 402 insufficient_balance; the budget is a cap, not money: the project first spends what was paid into it, then your account balance pays, call by call, up to the cap (with hard_cap false there is no cap, but the spend still needs paid funds or a balance above zero); when token_hard_capis true and projected token usage would exceed token_limit, the gate refuses with 402 insufficient_token_quota— both checks happen before any billable work begins, so over-budget requests are never charged. The token check runs first; the response code lets clients tell the two refusals apart. Every amount — budgets, payments, balances — is in US dollars: a project's currency is always USD, the default when you send none.

In this section
  1. POSTCreate/api/v1/projects
  2. GETList/api/v1/projects
  3. PUTBulk cache lifetime/api/v1/projects/cache-ttl
  4. PUTBulk model and effort/api/v1/projects/defaults
  5. GETRead/api/v1/projects/{projectId}
  6. PUTUpdate/api/v1/projects/{projectId}
  7. GETProject balance/api/v1/projects/{projectId}/balance
  8. DELETEDelete/api/v1/projects/{projectId}
Shell variables used in project examples
export BASE="https://ainvented.com"
export API_KEY="your_admin_api_key"
export PID="your_project_id"
export PID_2="another_project_id"   # for the examples that name two projects
# The account-wide bulk endpoints below refuse a project-scoped key with 403, so their
# examples name the variable ADMIN_KEY to make that requirement obvious. Same value.
export ADMIN_KEY="$API_KEY"
POST/api/v1/projects#

Create chat project

Creates a chat project, its initial API key, and its initial budget in a single transaction. Refused with 402 insufficient_balance (code negative_balance) while your account balance is negative — add credits first. The full API key is returned ONCE; subsequent reads expose only the partial key.

Authentication

Bearer <api_key> — must be an Admin key (no project binding). See the Authentication section above for the scope rules.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "type": "\"chat\" | \"function\" | \"canvas\"",
  "budget_cents": "integer cents",
  "currency": "\"USD\"",
  "alert_thresholds": "integer[]",
  "hard_cap": "boolean",
  "token_limit": "integer",
  "token_hard_cap": "boolean",
  "web_search_enabled": "boolean",
  "prompt_cache_enabled": "boolean",
  "prompt_cache_ttl_hours": "string|integer|null",
  "preconfigured_model": "'ainvented-eon' | 'ainvented-epic' | 'ainvented-saga' | 'ainvented-lite' | 'ainvented-low'",
  "preconfigured_effort": "'low' | 'medium' | 'high' | 'xhigh' | 'max'"
}
Fields13Expand
name
stringrequired
1..40
type
"chat" | "function" | "canvas"optional
default "chat" — also accepts legacy integers 1=chat, 2=function, 3=canvas. Any other value returns 400 invalid_request_error with param="type".
budget_cents
integer centsoptional
default 0 — the spending CAP. It adds no money: the project spends what was paid into it first, then your account balance pays, call by call, up to this cap
currency
"USD"optional
default "USD" — every amount is in US dollars; any other value is refused with 400
alert_thresholds
integer[]optional
strictly ascending, max 20, each 1..100, default [50,80,95,100]
hard_cap
booleanoptional
default true — refuse the request when consumed >= budget. false = no cap; the spend still needs paid funds or a balance above zero
token_limit
integeroptional
default 0 — max tokens this project can consume. 0 = unlimited.
token_hard_cap
booleanoptional
default false — when true, refuse with 402 insufficient_token_quota once consumed_tokens + estTokens > token_limit
web_search_enabled
booleanoptional
DEFAULT FALSE — "web search". When true, public http(s) URLs the end-user types in their message TEXT are fetched and read by the assistant in /v1/chat/completions. Set true to enable: only message-text URLs are affected — attached project files, `image_url` parts, and audio are always forwarded either way. Does not change billing.
prompt_cache_enabled
booleanoptional
default true — prompt caching for this project. When enabled (the default), repeated prompt prefixes are served from cache and billed at the discounted cached rate, lowering consumption at no quality cost. Set false to opt this project out — its requests bill cached input tokens at the full input rate. A per-request `prompt_cache` field overrides this per call.
prompt_cache_ttl_hours
string|integer|nulloptional
Managed Prompt Cache for this project, a single unified selector: 1, 6, 12 or 24 (fixed hours), "auto" (hand the lifetime to the optimizer, which continuously picks the best TTL to maximize this project's net cache savings), or null to disable (default). Keeps the project prompt prefix (>=1,024 tokens) cached for a guaranteed lifetime so every reuse bills at the cached rate. Storage: $1.50 per 1M tokens/hour + $0.40 per 1M one-time write. Same options and pricing for both models.
preconfigured_model
'ainvented-eon' | 'ainvented-epic' | 'ainvented-saga' | 'ainvented-lite' | 'ainvented-low'optional
default 'ainvented-lite'; 'ainvented-eon' where GET /v1/models lists it — the project's DEFAULT chat model tier, used by /v1/chat/completions when the caller omits the `model` field, and by every turn the project serves that cannot name a model per request: channel (connector) messages, scheduled tasks, evaluation judges without a tier of their own, vector-store answers, the builder's AI helpers, and workflow nodes with no node or workflow selection. An explicit request `model` always overrides this. 'ainvented-low' is the lower-cost tier (see the pricing page). The response echoes the value you sent; later reads report the Lite tier by its earlier id (unchanged for compatibility).
preconfigured_effort
'low' | 'medium' | 'high' | 'xhigh' | 'max'optional
the project's DEFAULT reasoning effort, used by /v1/chat/completions when the caller omits the `reasoning_effort` field and by the same project-served turns as `preconfigured_model` (connectors, scheduled tasks, judges, vector-store answers, the builder's AI helpers, workflow nodes with no selection of their own). An explicit request `reasoning_effort` always overrides this. Omit it and the project stays on the selected tier's standard effort.

Response Schema

JSON type shapeExpand
{
  "id": "uuid",
  "name": "string",
  "type": "integer",
  "type_name": "\"chat\" | \"function\" | \"canvas\"",
  "api_key": {
    "id": "uuid",
    "key": "full key",
    "partialKey": "last 4 chars"
  },
  "budget": {
    "budget_cents": "number",
    "consumed_cents": "number",
    "remaining_cents": "number",
    "remaining_pct": "number",
    "currency": "string",
    "hard_cap": "boolean",
    "alert_thresholds": "number[]",
    "fired_thresholds": "number[]",
    "token_limit": "number",
    "consumed_tokens": "number",
    "remaining_tokens": "number",
    "remaining_tokens_pct": "number",
    "token_hard_cap": "boolean",
    "fired_token_thresholds": "number[]",
    "credited_cents": "number",
    "credited_remaining_cents": "number",
    "paid_from_balance_cents": "number",
    "draws_from_balance": "boolean"
  },
  "web_search_enabled": "boolean",
  "prompt_cache_enabled": "boolean",
  "prompt_cache_ttl_hours": "string|integer|null",
  "preconfigured_model": "string",
  "preconfigured_effort": "string|null",
  "created_at": "ISO timestamp"
}
Fields33Expand
id
uuid
name
string
type
integer
DEPRECATED. Kept for backward compatibility with pre-2026-05 clients. Use type_name instead.
type_name
"chat" | "function" | "canvas"
canonical project kind.
api_key
object
object — fields below
id
uuid
key
full key
returned only once
partialKey
last 4 chars
budget
object
object — fields below
budget_cents
number
consumed_cents
number
remaining_cents
number
remaining_pct
number
currency
string
hard_cap
boolean
alert_thresholds
number[]
fired_thresholds
number[]
token_limit
number
consumed_tokens
number
remaining_tokens
number
remaining_tokens_pct
number
token_hard_cap
boolean
fired_token_thresholds
number[]
credited_cents
number
paid into the project (payments, auto-recharges, credits), net of refunds and chargebacks
credited_remaining_cents
number
what the project can still spend before your balance pays
paid_from_balance_cents
number
what your balance has paid of this project’s spend
draws_from_balance
boolean
the next call is charged to your balance (paid funds used up, cap not reached)
web_search_enabled
boolean
the effective value of the project you just created: false unless you explicitly sent web_search_enabled:true. Omitting the field creates the project with URL reading OFF and writes no settings row, and this field reports that.
prompt_cache_enabled
boolean
effective value (true unless explicitly set to false)
prompt_cache_ttl_hours
string|integer|null
managed-cache value: "auto" (optimizer-managed), a fixed TTL in hours, or null (not configured)
preconfigured_model
string
the value sent on create; when none was sent, the Lite tier, reported by its earlier id (unchanged for compatibility)
preconfigured_effort
string|null
effective default reasoning effort ('low' | 'medium' | 'high' | 'xhigh' | 'max'), or null when the project inherits the tier's standard effort
created_at
ISO timestamp

Code Examples

Create a chat project with a $250 budget AND a 1 000 000-token hard cap. Using the canonical string for `type`.

curl -X POST $BASE/api/v1/projects \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "qa-prod-1",
    "type": "chat",
    "budget_cents": 25000,
    "currency": "USD",
    "alert_thresholds": [50, 80, 95, 100],
    "hard_cap": true,
    "token_limit": 1000000,
    "token_hard_cap": true
  }'

Submitting an unsupported value returns a structured error listing the allowed values.

curl -X POST $BASE/api/v1/projects \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "x", "type": "pigeon"}'

# Response — 400 Bad Request
# {
#   "error": {
#     "message": "Invalid project type. Allowed string values: \"chat\", \"function\", \"canvas\"; legacy integer values: 1, 2, 3.",
#     "type": "invalid_request_error",
#     "param": "type"
#   }
# }
GET/api/v1/projects#

List projects for the authenticated user

Returns the projects owned by the API key's user, with a budget summary per row. Without query parameters it returns every non-deleted project, newest first (the original behaviour, unchanged). Add any of the query parameters below to switch to the PAGED mode — sorted and filtered on the server, one page at a time — which is what the Partner Console's projects table uses and what an account with thousands of projects should use.

Authentication

Bearer <api_key> — must be an Admin key (no project binding).

Request Schema

JSON type shapeExpand
{
  "limit": "integer 1..200 (query, optional; default 50)",
  "offset": "integer >= 0 (query, optional; default 0)",
  "sort": "\"name\" | \"created_at\" | \"expiration_date\" | \"consumed_cents\" | \"budget_cents\" | \"remaining_cents\" | \"consumed_tokens\" (query, optional; default \"created_at\")",
  "dir": "\"asc\" | \"desc\" (query, optional)",
  "q": "string, max 80 (query, optional)",
  "status": "\"active\" | \"disabled\" | \"all\" (query, optional; default \"active\")"
}
Fields6Expand
limit
integer 1..200 (query, optional; default 50)
page size. Sending it (or any parameter below) selects the paged mode.
offset
integer >= 0 (query, optional; default 0)
rows to skip.
sort
"name" | "created_at" | "expiration_date" | "consumed_cents" | "budget_cents" | "remaining_cents" | "consumed_tokens" (query, optional; default "created_at")
dir
"asc" | "desc" (query, optional)
default "asc" for name, "desc" for everything else.
q
string, max 80 (query, optional)
case-insensitive substring of the project name, or a prefix of the project id.
status
"active" | "disabled" | "all" (query, optional; default "active")
"active" matches the unpaged mode (non-deleted projects only).

Response Schema

JSON type shapeExpand
{
  "data": [
    {
      "id": "uuid",
      "name": "string",
      "type": "integer",
      "type_name": "\"chat\" | \"function\" | \"canvas\"",
      "disabled": "boolean",
      "created_at": "ISO",
      "expiration_date": "ISO",
      "prompt_cache_ttl_hours": "string|integer|null",
      "budget": {
        "budget_cents": "number",
        "consumed_cents": "number",
        "currency": "string",
        "hard_cap": "boolean",
        "token_limit": "number",
        "consumed_tokens": "number",
        "remaining_tokens": "number",
        "remaining_tokens_pct": "number",
        "token_hard_cap": "boolean"
      }
    }
  ],
  "page": "{ limit, offset, total, has_more }",
  "sort": "{ key, dir }",
  "filters": "{ q: string|null, status }"
}
Fields22Expand
data
array
array — fields below
id
uuid
name
string
type
integer
DEPRECATED. Use type_name.
type_name
"chat" | "function" | "canvas"
disabled
boolean
created_at
ISO
expiration_date
ISO
paged mode only (the renewal date)
prompt_cache_ttl_hours
string|integer|null
managed-cache value: "auto" (optimizer-managed), a fixed TTL in hours, or null (off)
budget
object
object — fields below
budget_cents
number
consumed_cents
number
currency
string
hard_cap
boolean
token_limit
number
consumed_tokens
number
remaining_tokens
number
remaining_tokens_pct
number
token_hard_cap
boolean
page
{ limit, offset, total, has_more }
paged mode only
sort
{ key, dir }
paged mode only: the sort actually applied
filters
{ q: string|null, status }
paged mode only

Code Examples

curl $BASE/api/v1/projects -H "Authorization: Bearer $API_KEY"

The second page of 50, the most-consumed first, only projects whose name contains "shop".

curl "$BASE/api/v1/projects?limit=50&offset=50&sort=consumed_cents&dir=desc&q=shop&status=active" \
  -H "Authorization: Bearer $API_KEY"

# {
#   "data": [ { "id": "…", "name": "shop-eu", "expiration_date": "…", "budget": { … } }, … ],
#   "page": { "limit": 50, "offset": 50, "total": 1284, "has_more": true },
#   "sort": { "key": "consumed_cents", "dir": "desc" },
#   "filters": { "q": "shop", "status": "active" }
# }
PUT/api/v1/projects/cache-ttl#

Bulk: set the managed-cache value on all (or selected) projects

Batch-applies one Managed Prompt Cache value to every project of your account — or to a chosen subset — in a single call, the API twin of the partner console's 'apply to all projects' button. Accepts a fixed TTL, 'auto' (hand every project to the optimizer), or null (off). Projects without a settings row get one created. Safe at any scale: a project whose prompts are never reused mints no cache and pays no storage (creation requires the prefix to be seen 3 times within 10 minutes). Audit log emits one project.prompt_cache_ttl.set row per project whose value actually changed.

Authentication

Bearer <api_key> — must be an Admin key (no project binding).

Request Schema

JSON type shapeExpand
{
  "prompt_cache_ttl_hours": "string|integer|null",
  "project_ids": "array"
}
Fields2Expand
prompt_cache_ttl_hours
string|integer|nullrequired
1, 6, 12 or 24 hours, "auto" (optimizer-managed on every project), or null to disable on every project. Same semantics, minimum prompt size (1,024 tokens) and pricing ($1.50 per 1M tokens/hour storage + $0.40 per 1M one-time write) as the per-project setting.
project_ids
arrayoptional
up to 1000 project UUIDs to scope the apply to. OMIT to apply to every non-deleted project of your account (the default, and the only behaviour before this field existed). Ids you do not own are simply not matched, and duplicates are collapsed, so `updated` always reflects the projects actually written.

Response Schema

JSON type shapeExpand
{
  "updated": "integer",
  "prompt_cache_ttl_hours": "string|integer|null"
}
Fields2Expand
updated
integer
number of projects the value was applied to
prompt_cache_ttl_hours
string|integer|null
the applied value

Code Examples

curl -X PUT $BASE/api/v1/projects/cache-ttl \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt_cache_ttl_hours": "auto"}'
curl -X PUT $BASE/api/v1/projects/cache-ttl \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt_cache_ttl_hours": 6, "project_ids": ["<uuid-1>", "<uuid-2>"]}'
PUT/api/v1/projects/defaults#

Bulk: set the default model and reasoning effort on all (or selected) projects

Batch-applies a default model and/or a default reasoning effort to every project of your account — or to a chosen subset — in a single call, instead of one PUT per project. Both fields are the values used when a request omits `model` / `reasoning_effort`; a request that names either is unaffected. Send at least one of the two (an empty patch returns 400). Projects without a settings row get one created. BILLING: the default model decides which tier's input, cached-input and output rate an unnamed-model request is billed at, and a higher default effort spends more output tokens per turn — on a request that sets its own max_tokens, that cap bounds the visible answer only and thinking tokens are billed on top of it. Channel (connector) messages, scheduled tasks, evaluation judges that name no tier of their own, vector-store answers and the builder's AI helpers cannot name a model or an effort per request, so BOTH defaults apply to them: they are served on the project's default tier at the project's default effort and billed at that tier's rates. A workflow follows its own selection first (a node's pin, then the workflow default) and falls back to the project default. Pinning a premium tier therefore changes what serves every turn of the project, not only its price. Audit log emits one project.preconfigured_model.set and/or project.preconfigured_effort.set row per project whose stored value actually changed, so every repricing stays attributable to the account that made it; re-applying a value a project already holds writes no row.

Authentication

Bearer <api_key> — must be an Admin key (no project binding).

Request Schema

JSON type shapeExpand
{
  "preconfigured_model": "string",
  "preconfigured_effort": "string|null",
  "project_ids": "array"
}
Fields3Expand
preconfigured_model
stringoptional
"ainvented-eon" where GET /v1/models lists it, "ainvented-epic", "ainvented-saga", "ainvented-lite" or "ainvented-low". "ainvented-lite" clears any override back to the default (Lite) tier.
preconfigured_effort
string|nulloptional
"low", "medium", "high", "xhigh" or "max", or null to clear the override so each project inherits its tier's own default effort.
project_ids
arrayoptional
up to 1000 project UUIDs to scope the apply to. OMIT to apply to every non-deleted project of your account. Ids you do not own are simply not matched, and duplicates are collapsed, so `updated` always reflects the projects actually written.

Response Schema

JSON type shapeExpand
{
  "updated": "integer",
  "preconfigured_model": "string",
  "preconfigured_effort": "string|null"
}
Fields3Expand
updated
integer
number of projects the value was applied to
preconfigured_model
string
echoed only when preconfigured_model was included in the request
preconfigured_effort
string|null
echoed only when preconfigured_effort was included in the request

Code Examples

curl -X PUT $BASE/api/v1/projects/defaults \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{"preconfigured_model": "ainvented-low", "preconfigured_effort": "medium"}'
curl -X PUT $BASE/api/v1/projects/defaults \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{"preconfigured_effort": null, "project_ids": ["<uuid-1>", "<uuid-2>"]}'
GET/api/v1/projects/{projectId}#

Read a project (with counts)

Returns the project, its full budget snapshot, and component counts (connectors, skills, workflows). A deleted project returns 404.

Authentication

Bearer <api_key> — must own the project.

Response Schema

JSON type shapeExpand
{
  "id": "uuid",
  "name": "string",
  "type": "integer",
  "type_name": "\"chat\" | \"function\" | \"canvas\"",
  "disabled": "boolean",
  "created_at": "ISO",
  "budget": "BudgetSnapshot",
  "preconfigured_model": "string",
  "default_model": "string",
  "web_search_enabled": "boolean",
  "prompt_cache_enabled": "boolean",
  "prompt_cache_ttl_hours": "string|integer|null",
  "preconfigured_effort": "string|null",
  "counts": {
    "connector": "number",
    "skill": "number",
    "workflow": "number"
  }
}
Fields17Expand
id
uuid
name
string
type
integer
DEPRECATED. Use type_name.
type_name
"chat" | "function" | "canvas"
disabled
boolean
created_at
ISO
budget
BudgetSnapshot
preconfigured_model
string
the effective default model for this project, as the neutral alias: the tier you wrote as preconfigured_model on create / update / bulk. The Lite tier — written as "ainvented-lite", or never set — is reported by its earlier id, unchanged for compatibility; every other tier under its own id ("ainvented-eon" | "ainvented-epic" | "ainvented-saga" | "ainvented-low").
default_model
string
the same value under its original read-side name, kept for existing readers. This is the READ-side name of the value written as preconfigured_model by create, update and the bulk defaults endpoint.
web_search_enabled
boolean
whether public URLs typed in a message are fetched for this project
prompt_cache_enabled
boolean
the caching on/off switch; false bills every input token at the full rate
prompt_cache_ttl_hours
string|integer|null
the project's managed-cache value: "auto" (optimizer-managed), a fixed TTL in hours, or null (not configured / off)
preconfigured_effort
string|null
the project's default reasoning effort ('low' | 'medium' | 'high' | 'xhigh' | 'max'), omitted when it inherits the tier's standard effort
counts
object
object — fields below
connector
number
skill
number
workflow
number

Code Examples

curl $BASE/api/v1/projects/$PID -H "Authorization: Bearer $API_KEY"
PUT/api/v1/projects/{projectId}#

Update a project

Patches name, budget_cents, currency, alert_thresholds, hard_cap, disabled, token_limit, token_hard_cap, web_search_enabled, prompt_cache_enabled, prompt_cache_ttl_hours, and preconfigured_effort. Currency cannot be changed once consumed_cents > 0 (returns 409). Managed cache is a single unified selector: setting prompt_cache_ttl_hours to 'auto' hands the lifetime to the optimizer; a number/null sets a fixed TTL and turns auto off — there is no separate flag and no manual/auto interlock. Updating alert_thresholds re-arms BOTH fired_thresholds and fired_token_thresholds; updating token_limit re-arms fired_token_thresholds. Lowering token_limit below current consumed_tokens is allowed and is not retroactive — the next request is evaluated against the new limit. Empty patch returns 400. Audit log emits project.token_limit.set and project.token_limit.cap_toggle, project.web_search.toggle, project.prompt_caching.toggle, project.prompt_cache_ttl.set, and project.preconfigured_effort.set, when the corresponding fields change.

Authentication

Bearer <api_key> — must own the project.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "budget_cents": "integer",
  "currency": "\"USD\"",
  "alert_thresholds": "integer[]",
  "hard_cap": "boolean",
  "disabled": "boolean",
  "token_limit": "integer",
  "token_hard_cap": "boolean",
  "web_search_enabled": "boolean",
  "prompt_cache_enabled": "boolean",
  "prompt_cache_ttl_hours": "string|integer|null",
  "preconfigured_model": "'ainvented-eon' | 'ainvented-epic' | 'ainvented-saga' | 'ainvented-lite' | 'ainvented-low'",
  "preconfigured_effort": "'low' | 'medium' | 'high' | 'xhigh' | 'max' | null"
}
Fields13Expand
name
stringoptional
1..40
budget_cents
integeroptional
currency
"USD"optional
every amount is in US dollars; any other value is refused with 400
alert_thresholds
integer[]optional
strictly ascending, max 20
hard_cap
booleanoptional
disabled
booleanoptional
token_limit
integeroptional
≥ 0 — 0 means unlimited
token_hard_cap
booleanoptional
web_search_enabled
booleanoptional
enable/disable fetching of public URLs typed in message TEXT ("web search") for this project. Only message-text URLs are affected; files, image_url parts, and audio are unaffected.
prompt_cache_enabled
booleanoptional
enable/disable prompt caching for this project. When false, requests bill cached input tokens at the full input rate.
prompt_cache_ttl_hours
string|integer|nulloptional
the unified Managed Prompt Cache selector: set a fixed TTL (1|6|12|24), "auto" (hand the lifetime to the optimizer), or null to disable. $1.50 per 1M tokens/hour storage while active. Selecting a fixed value/off turns auto off and vice-versa — no interlock.
preconfigured_model
'ainvented-eon' | 'ainvented-epic' | 'ainvented-saga' | 'ainvented-lite' | 'ainvented-low'optional
; 'ainvented-eon' where GET /v1/models lists it — set the project's DEFAULT chat model tier (used when /v1/chat/completions omits `model`). 'ainvented-lite' clears any override back to the default (Lite) model.
preconfigured_effort
'low' | 'medium' | 'high' | 'xhigh' | 'max' | nulloptional
set the project's DEFAULT reasoning effort (used when /v1/chat/completions omits `reasoning_effort`). null clears any override back to the tier's standard effort.

Response Schema

JSON type shapeExpand
{
  "id": "uuid",
  "name": "string",
  "disabled": "boolean",
  "budget": "BudgetSnapshot (includes token fields)",
  "web_search_enabled": "boolean",
  "prompt_cache_enabled": "boolean",
  "prompt_cache_ttl_hours": "string|integer|null",
  "preconfigured_model": "string",
  "preconfigured_effort": "string|null"
}
Fields9Expand
id
uuid
name
string
disabled
boolean
budget
BudgetSnapshot (includes token fields)
web_search_enabled
boolean
echoed only when web_search_enabled was included in the patch
prompt_cache_enabled
boolean
echoed only when prompt_cache_enabled was included in the patch
prompt_cache_ttl_hours
string|integer|null
echoed only when included in the patch ("auto" | fixed hours | null)
preconfigured_model
string
echoed only when preconfigured_model was included in the patch
preconfigured_effort
string|null
echoed only when preconfigured_effort was included in the patch ('low' | 'medium' | 'high' | 'xhigh' | 'max' | null)

Code Examples

Raise budget, tighten alerts, and switch to a 500 000-token hard cap.

curl -X PUT $BASE/api/v1/projects/$PID \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "budget_cents": 50000,
    "alert_thresholds": [25, 50, 75, 100],
    "token_limit": 500000,
    "token_hard_cap": true
  }'
DELETE/api/v1/projects/{projectId}#

Delete a project

Deletes the project, revokes all of its API keys and deactivates all of its webhooks. Idempotent: a second call returns 410. Subsequent reads return 404.

Authentication

Bearer <api_key> — must own the project.

Code Examples

curl -X DELETE $BASE/api/v1/projects/$PID -H "Authorization: Bearer $API_KEY"
Reference · 15 endpoints

Guardrails & Skills

A project's guardrails (rules every answer must respect) and skills (instructions that shape every answer) — the same ones the AI Chat Guardrails and Skills buttons edit. Every active one is applied to every chat turn of the project, in the chat UI and on /v1/chat/completions.

In this section
  1. GuideOverview
  2. GuideUse them in a chat request
  3. POSTChat with guardrails and skills/api/v1/chat/completions
  4. POSTCreate a guardrail/api/v1/projects/{projectId}/guardrails
  5. GETList guardrails/api/v1/projects/{projectId}/guardrails
  6. GETRead a guardrail/api/v1/projects/{projectId}/guardrails/{guardrailId}
  7. PUTUpdate a guardrail/api/v1/projects/{projectId}/guardrails/{guardrailId}
  8. DELETEDelete a guardrail/api/v1/projects/{projectId}/guardrails/{guardrailId}
  9. POSTCreate a skill/api/v1/projects/{projectId}/skills
  10. GETList skills/api/v1/projects/{projectId}/skills
  11. GETRead a skill/api/v1/projects/{projectId}/skills/{skillId}
  12. PUTUpdate a skill/api/v1/projects/{projectId}/skills/{skillId}
  13. DELETEDelete a skill/api/v1/projects/{projectId}/skills/{skillId}
  14. GuideAcross projects
  15. GETList across projects/api/v1/guardrails
  16. PUTAdd or update by name/api/v1/guardrails
  17. PATCHSwitch on or off by name/api/v1/guardrails
  18. DELETERemove by name/api/v1/guardrails

Overview

  • Keys. Managing them takes an Admin key that owns the project (API keys → Create API key → Scope: Admin). A project-scoped key is refused with 403 admin_key_required: the key you hand to an end customer cannot read or lift the project's rules — but it can still use them in chat requests.
  • Per request. Any key can ADD guardrails and skills to one request by sending them in tools on chat completions, or SELECT stored ones by name or id — see Use them in a chat request. Nothing is stored.
  • Active. is_active: false keeps one without applying it to every turn — it stays selectable per request. Changes apply from the next request.
  • Same everywhere. The ones made here, in AI Chat and in the Partner Console (project → Guardrails & Skills) are the same: a change in one shows in the others.
  • Names are unique per project and kind, ignoring case and extra spaces, so a chat request can select one by name: creating a second one with a name already in use is a 409 duplicate_name whose message gives the existing one's id.
  • Limits. name up to 100 characters, rule / prompt up to 1,000,000, a skill's description up to 2,000; up to 100 of each per project created through the API. Unknown fields are refused (400, param names them).
  • Cost. Free to manage. Each active one is part of every turn's input, billed as input tokens.
cURL — add a guardrail
curl -X POST $BASE/api/v1/projects/$PID/guardrails \
  -H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" \
  -d '{"name":"no-discounts","rule":"Never promise discounts or refunds."}'
Guide

Use them in a chat request

A chat turn applies the project's active guardrails and skills, then the ones the request brings — in that order, in the same blocks. A request can bring two kinds: stored ones it selects by name or id, and one-off ones it writes itself. Nothing a request sends can switch a stored one off.

Where it livesApplies toWhat the request sends in tools
Always onSaved on the project and active — made in AI Chat, in the Partner Console or with the endpoints below.Every chat turn of the project: AI Chat, the API, connected channels.Nothing.
On demandSaved on the project and switched off — a library to pick from.Only the request that selects it.{"type": "skill", "skill": {"name": "Formal tone"}} or {"type": "guardrail", "guardrail": {"id": "…"}}
One-offThe request itself. Nothing is saved.That request.{"type": "guardrail", "guardrail": {"rule": "Never promise discounts."}}, {"type": "skill", "skill": {"prompt": "…"}} — or just the text: {"type": "skill", "skill": "Answer formally."}
  • Selecting an active one changes nothing: it already applies. A row selected twice applies once.
  • Names match ignoring case and extra spaces (formal TONE selects Formal tone). Two rows with the same name? Select by id, or rename one.
  • Finding a name or an id. Partner Console → the project → Guardrails & Skills (each row has Copy ID); AI Chat → the Skills and Guardrails buttons (names); or GET /api/v1/projects/{projectId}/skills and /guardrails (ids and names).
  • Keys. Any key that can call chat completions can select stored ones or send one-off ones — the project's own key included (Partner Console → API keys). Creating, editing or deleting stored ones takes an Admin key.
  • Mixing. They sit next to your function tools, which keep their meaning: a tools array holding only guardrails and skills behaves as if tools were omitted (workflows auto-run as usual). Streaming works the same.
  • Up to 32 guardrails and 32 skills per request; one-off texts up to 1,000,000 characters combined.
  • Cost. They are part of the turn's input and billed as input tokens. A refused request (below) costs nothing.
400 codeWhat happenedWhat to do
skill_not_found / guardrail_not_foundNo stored one with that name or id in this project (param names the entry, e.g. tools[0].skill.name).Check the name, or copy the id from the Partner Console. With an Admin key the message suggests the name you most likely meant (Did you mean 'Formal tone'?), or lists the project's names, closest first.
ambiguous_skill / ambiguous_guardrailTwo stored ones share that name.Select it by id, or rename one.
invalid_skill / invalid_guardrailA malformed entry: an empty text, an id that is not a UUID, both id and a text, an id and a name of different rows.Fix the field param names.
too_many_skills / too_many_guardrailsMore than 32 of a kind in one request.Send fewer — keep the ones every request needs active on the project instead.
inline_directives_too_largeOne-off texts over 1,000,000 characters combined.Save the long ones on the project and select them by name.

All of these are answered before any model is called: nothing is spent, nothing is billed.

POST/api/v1/chat/completions#

Chat with guardrails and skills

The chat completions call, with guardrails and skills in tools: select stored ones by name or id, or send one-off ones. Everything else about the call is unchanged (see Chat Completions).

Authentication

Bearer <api_key> — any key that can call chat completions (a project-scoped key included).

Request Schema

JSON type shapeExpand
{
  "tools[].type": "'skill' | 'guardrail'",
  "tools[].skill": "{ name } or { id }",
  "tools[].guardrail": "{ name } or { id }"
}
Fields3Expand
tools[].type
'skill' | 'guardrail'
next to your 'function' tools
tools[].skill
{ name } or { id }
a stored skill (an inactive one applies to this request only); { prompt, name?, description? } or a string — a one-off skill
tools[].guardrail
{ name } or { id }
a stored guardrail; { rule, name? } or a string — a one-off guardrail

Response Schema

JSON type shapeExpand
{
  "choices": "[{ message: { role: 'assistant', content } }]",
  "usage": "{ prompt_tokens, completion_tokens, total_tokens }",
  "error": "{ message, type, param, code }"
}
Fields3Expand
choices
[{ message: { role: 'assistant', content } }]
the answer, held to every guardrail and skill that applied
usage
{ prompt_tokens, completion_tokens, total_tokens }
guardrails and skills count as input
error
{ message, type, param, code }
on a 400, before any model call (see the guide above)

Code Examples

curl https://ainvented.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "A customer asks for a discount on their renewal. Write a two-sentence reply."}],
    "tools": [
      {"type": "skill", "skill": {"name": "Formal tone"}},
      {"type": "guardrail", "guardrail": {"id": "3f1c2b4a-5d6e-4f70-8a9b-0c1d2e3f4a5b"}},
      {"type": "guardrail", "guardrail": "Never ask for card numbers."}
    ]
  }'
# A stored one that is INACTIVE applies to this request only: keep a library of
# on-demand skills and rules switched off, and pick them per request.
# An ACTIVE one already applies to every request; selecting it changes nothing.
# Names match ignoring case and spacing. Unknown: 400 skill_not_found (param tools[0].skill.name).
import requests

BASE = "https://ainvented.com"
KEY = "YOUR_API_KEY"  # the project's key (Partner Console → API keys) works

r = requests.post(
    f"{BASE}/api/v1/chat/completions",
    headers={"Authorization": f"Bearer {KEY}"},
    json={
        "messages": [{"role": "user", "content": "A customer asks for a discount on their renewal. Write a two-sentence reply."}],
        "tools": [
            {"type": "skill", "skill": {"name": "Formal tone"}},  # a stored skill, by name
            {"type": "guardrail", "guardrail": {"id": "3f1c2b4a-5d6e-4f70-8a9b-0c1d2e3f4a5b"}},  # a stored guardrail, by id
            {"type": "guardrail", "guardrail": "Never ask for card numbers."},  # a one-off rule
        ],
    },
    timeout=120,
)
body = r.json()
if r.status_code == 400:  # e.g. skill_not_found at tools[0].skill.name — nothing was billed
    raise SystemExit(f"{body['error']['code']} at {body['error']['param']}: {body['error']['message']}")
print(body["choices"][0]["message"]["content"])
const BASE = 'https://ainvented.com';
const KEY = process.env.AINVENTED_API_KEY; // the project's key (Partner Console → API keys) works

const res = await fetch(`${BASE}/api/v1/chat/completions`, {
  method: 'POST',
  headers: { Authorization: `Bearer ${KEY}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    messages: [{ role: 'user', content: 'A customer asks for a discount on their renewal. Write a two-sentence reply.' }],
    tools: [
      { type: 'skill', skill: { name: 'Formal tone' } }, // a stored skill, by name
      { type: 'guardrail', guardrail: { id: '3f1c2b4a-5d6e-4f70-8a9b-0c1d2e3f4a5b' } }, // a stored guardrail, by id
      { type: 'guardrail', guardrail: 'Never ask for card numbers.' }, // a one-off rule
    ],
  }),
});
const body = await res.json();
// a 400 (e.g. skill_not_found at tools[0].skill.name) is answered before any model call — nothing is billed
if (!res.ok) throw new Error(`${body.error.code} at ${body.error.param}: ${body.error.message}`);
console.log(body.choices[0].message.content);
POST/api/v1/projects/{projectId}/guardrails#

Create a guardrail

Adds a guardrail to the project. 409 duplicate_name when another guardrail already has the name (ignoring case and spaces — the message gives its id); 409 guardrail_limit_reached at 100; 403 project_disabled on a disabled project.

Authentication

Bearer <api_key> — Admin key that owns the project.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "rule": "string",
  "is_active": "boolean"
}
Fields3Expand
name
stringrequired
≤100
rule
stringrequired
≤1,000,000 — the rule, written as an instruction
is_active
booleanoptional
default true

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'guardrail'",
  "project_id": "uuid",
  "name": "string",
  "rule": "string",
  "is_active": "boolean",
  "created_at": "ISO",
  "updated_at": "ISO"
}
Fields8Expand
id
string
object
'guardrail'
project_id
uuid
name
string
rule
string
is_active
boolean
created_at
ISO
updated_at
ISO
GET/api/v1/projects/{projectId}/guardrails#

List guardrails

Every guardrail of the project, oldest first. ?is_active=true|false filters.

Authentication

Bearer <api_key> — Admin key that owns the project.

Response Schema

JSON type shapeExpand
{
  "object": "'list'",
  "data": "Guardrail[]"
}
Fields2Expand
object
'list'
data
Guardrail[]

Code Examples

curl "$BASE/api/v1/projects/$PID/guardrails?is_active=true" -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/guardrails/{guardrailId}#

Read a guardrail

One guardrail. 404 guardrail_not_found when it is not in this project.

Authentication

Bearer <api_key> — Admin key that owns the project.

PUT/api/v1/projects/{projectId}/guardrails/{guardrailId}#

Update a guardrail

Change its name, rule or is_active (send only what changes). PATCH on the same path does the same. A new name another guardrail has is a 409 duplicate_name.

Authentication

Bearer <api_key> — Admin key that owns the project.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "rule": "string",
  "is_active": "boolean"
}
Fields3Expand
name
stringoptional
rule
stringoptional
is_active
booleanoptional

Code Examples

curl -X PUT $BASE/api/v1/projects/$PID/guardrails/$GUARDRAIL_ID \
  -H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" -d '{"is_active":false}'
DELETE/api/v1/projects/{projectId}/guardrails/{guardrailId}#

Delete a guardrail

Removes it from the project, like the delete button in AI Chat. It stops applying from the next request.

Authentication

Bearer <api_key> — Admin key that owns the project.

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'guardrail'",
  "deleted": "true"
}
Fields3Expand
id
string
object
'guardrail'
deleted
true
POST/api/v1/projects/{projectId}/skills#

Create a skill

Adds a skill to the project. 409 duplicate_name when another skill already has the name (ignoring case and spaces — the message gives its id); 409 skill_limit_reached at 100; 403 project_disabled on a disabled project.

Authentication

Bearer <api_key> — Admin key that owns the project.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "prompt": "string",
  "description": "string | null",
  "type": "'instruction' (default) | 'tool'",
  "is_active": "boolean"
}
Fields5Expand
name
stringrequired
≤100
prompt
stringrequired
≤1,000,000 — the instructions
description
string | nulloptional
≤2,000 — what it is for (not sent to the model)
type
'instruction' (default) | 'tool'optional
a label; every skill is applied the same way
is_active
booleanoptional
default true

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'skill'",
  "project_id": "uuid",
  "name": "string",
  "description": "string|null",
  "prompt": "string",
  "type": "string",
  "is_active": "boolean",
  "created_at": "ISO",
  "updated_at": "ISO"
}
Fields10Expand
id
string
object
'skill'
project_id
uuid
name
string
description
string|null
prompt
string
type
string
is_active
boolean
created_at
ISO
updated_at
ISO

Code Examples

curl -X POST $BASE/api/v1/projects/$PID/skills \
  -H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" \
  -d '{"name":"formal","prompt":"Answer in a formal tone, in at most three sentences."}'
GET/api/v1/projects/{projectId}/skills#

List skills

Every skill of the project, oldest first. ?is_active=true|false filters.

Authentication

Bearer <api_key> — Admin key that owns the project.

Response Schema

JSON type shapeExpand
{
  "object": "'list'",
  "data": "Skill[]"
}
Fields2Expand
object
'list'
data
Skill[]
GET/api/v1/projects/{projectId}/skills/{skillId}#

Read a skill

One skill. 404 skill_not_found when it is not in this project.

Authentication

Bearer <api_key> — Admin key that owns the project.

PUT/api/v1/projects/{projectId}/skills/{skillId}#

Update a skill

Change its name, prompt, description, type or is_active (send only what changes; description: null clears it). PATCH on the same path does the same. A new name another skill has is a 409 duplicate_name.

Authentication

Bearer <api_key> — Admin key that owns the project.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "prompt": "string",
  "description": "string|null",
  "type": "'instruction'|'tool'",
  "is_active": "boolean"
}
Fields5Expand
name
stringoptional
prompt
stringoptional
description
string|nulloptional
type
'instruction'|'tool'optional
is_active
booleanoptional
DELETE/api/v1/projects/{projectId}/skills/{skillId}#

Delete a skill

Removes it from the project. It stops applying from the next request.

Authentication

Bearer <api_key> — Admin key that owns the project.

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "object": "'skill'",
  "deleted": "true"
}
Fields3Expand
id
string
object
'skill'
deleted
true
Guide

Across projects

Put one guardrail or skill on every project of your account — or on a batch you choose — in one call, by name; switch it on or off, or remove it, the same way. Each project still keeps its own copy: the per-project endpoints above (and AI Chat) edit one project's. The Partner Console does this under All projects → Guardrails & Skills.

  • Keys. Admin key only — a project-scoped key is refused with 403 admin_key_required, whatever projects it names.
  • Scope. Without project_ids: every project of the account (disabled ones excepted). With project_ids (up to 1,000 UUIDs): only those — an id that is not one of your projects is simply not touched.
  • By name. Matched ignoring case and extra spaces, the way a chat request selects one. A project holding two with the same name (AI Chat allows it) has both changed.
  • Add or update. PUT adds it where a project has none with the name. Where it has one, if_exists: "update" (the default) writes only the fields you send that differ — on/off, a skill's description and type stay as each project has them unless you send them — and "skip" leaves it alone. A project already at 100 reports limit_reached; the others go ahead.
  • Per project. The answer lists every project in scope with its status — created, updated, unchanged, skipped, limit_reached, not_found, deleted or failed — and the counts of each. One project failing never stops the others, and sending the same call again is safe: what already matches reports unchanged.
  • When. Each project's next request follows it. Every change is recorded per project with its full before and after text.
  • Busy. A write may answer 429 server_overloaded with Retry-After when the service is under heavy load — nothing was changed; send it again.
  • Skills. The same four calls at /api/v1/skills, with prompt (and optionally description, type) in place of rule.
  • Cost. Free to manage; each active one is part of every turn's input, billed as input tokens.
cURL — one guardrail on every project
curl -X PUT $BASE/api/v1/guardrails \
  -H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" \
  -d '{"name":"No competitor mentions","rule":"Never mention or compare against competitor products by name."}'
GET/api/v1/guardrails#

List across projects

Every guardrail of every project in scope, oldest first — or, with group_by=name, folded by name: in how many projects each one is, how many have it on or off, and how many versions of its text there are. Same call at /api/v1/skills.

Authentication

Bearer <api_key> — Admin key.

Request Schema

JSON type shapeExpand
{
  "project_ids": "query",
  "name": "query",
  "is_active": "query",
  "group_by": "query"
}
Fields4Expand
project_ids
queryoptional
comma-separated project UUIDs; default every project of the account
name
queryoptional
only this name (case and extra spaces ignored)
is_active
queryoptional
'true' | 'false'
group_by
queryoptional
'name'

Response Schema

JSON type shapeExpand
{
  "object": "'list'",
  "projects": "number",
  "data": "Guardrail[]"
}
Fields3Expand
object
'list'
projects
number
projects in scope
data
Guardrail[]
or, with group_by=name, { name, text (the most common), texts[], variants, projects, active, inactive, items: [{ project_id, id, is_active, variant }] }[]

Code Examples

curl "$BASE/api/v1/guardrails?group_by=name" -H "Authorization: Bearer $ADMIN_KEY"
{
  "object": "list",
  "projects": 3,
  "data": [
    {
      "object": "guardrail_group",
      "name": "No competitor mentions",
      "text": "Never mention or compare against competitor products by name.",
      "variants": 2,
      "texts": [
        "Never mention or compare against competitor products by name.",
        "Never name a competitor."
      ],
      "projects": 3,
      "active": 2,
      "inactive": 1,
      "items": [
        { "project_id": "3f6c2a8e-91d4-4b7a-a5e2-6d0c8b1f4e27", "id": "9c4e7a2b-58d1-4f6a-b3e0-2d8f1c6a9b74", "is_active": true, "same_text": true, "variant": 0 },
        { "project_id": "7a1d5e9c-2b48-4f03-8e6a-c9d2f0b7a415", "id": "1e8b3d6f-4a92-4c7e-8b15-f6a0d3c9e271", "is_active": true, "same_text": true, "variant": 0 },
        { "project_id": "c8b2f6d4-0e37-4a95-9c1d-5b7e3a2f8d06", "id": "6f2a9c1e-7d34-4b8a-a0e6-9e4c1b5d7f32", "is_active": false, "same_text": false, "variant": 1 }
      ]
    }
  ]
}
PUT/api/v1/guardrails#

Add or update by name

Puts one guardrail on every project in scope: added where a project has none with the name, updated (if_exists: 'update', the default — only the fields you send) or left alone ('skip') where it has one. Same call at /api/v1/skills with prompt, description and type.

Authentication

Bearer <api_key> — Admin key.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "rule": "string",
  "is_active": "boolean",
  "if_exists": "'update' (default) | 'skip'",
  "project_ids": "uuid[]"
}
Fields5Expand
name
stringrequired
≤100 — matched across projects
rule
stringrequired
≤1,000,000 — skills: prompt; plus description (string|null) and type (optional)
is_active
booleanoptional
new copies default to true; omitted, existing ones keep their own
if_exists
'update' (default) | 'skip'
project_ids
uuid[]optional
≤1,000 — default every project of the account

Response Schema

JSON type shapeExpand
{
  "object": "'bulk_result'",
  "kind": "'guardrail' | 'skill'",
  "action": "'apply'",
  "name": "string",
  "projects": "number",
  "counts": "{ created, updated, unchanged, skipped, limit_reached, not_found, deleted, failed }",
  "results": "[{ project_id, status, id?, rows?, message? }]"
}
Fields7Expand
object
'bulk_result'
kind
'guardrail' | 'skill'
action
'apply'
name
string
projects
number
counts
{ created, updated, unchanged, skipped, limit_reached, not_found, deleted, failed }
results
[{ project_id, status, id?, rows?, message? }]
one per project in scope

Code Examples

# PID and PID_2: two of your projects
curl -X PUT "$BASE/api/v1/skills" \
  -H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" \
  --data @- <<JSON
{"name": "Concise", "prompt": "Answer in at most three sentences.", "if_exists": "skip",
 "project_ids": ["$PID", "$PID_2"]}
JSON
{
  "object": "bulk_result",
  "kind": "skill",
  "action": "apply",
  "name": "Concise",
  "projects": 2,
  "counts": { "created": 1, "updated": 0, "unchanged": 0, "skipped": 1, "limit_reached": 0, "not_found": 0, "deleted": 0, "failed": 0 },
  "results": [
    { "project_id": "3f6c2a8e-91d4-4b7a-a5e2-6d0c8b1f4e27", "status": "created", "id": "b2e9d4f1-07a3-4c6e-9d58-1a4f7c2e8b30", "rows": 1 },
    { "project_id": "7a1d5e9c-2b48-4f03-8e6a-c9d2f0b7a415", "status": "skipped", "id": "e5c3a8b7-6d12-4f9e-b0a4-3c7e1d9f2a68", "rows": 1 }
  ]
}
PATCH/api/v1/guardrails#

Switch on or off by name

Switches the guardrail with that name on or off in every project in scope that has it; projects without it report not_found. Same call at /api/v1/skills.

Authentication

Bearer <api_key> — Admin key.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "is_active": "boolean",
  "project_ids": "uuid[]"
}
Fields3Expand
name
stringrequired
is_active
booleanrequired
project_ids
uuid[]optional

Response Schema

JSON type shapeExpand
{
  "object": "'bulk_result'",
  "action": "'activate' | 'deactivate'",
  "counts": "{ … }",
  "results": "[{ project_id, status }]"
}
Fields4Expand
object
'bulk_result'
action
'activate' | 'deactivate'
counts
{ … }
results
[{ project_id, status }]

Code Examples

curl -X PATCH $BASE/api/v1/guardrails \
  -H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" \
  -d '{"name":"No competitor mentions","is_active":false}'
{
  "object": "bulk_result",
  "kind": "guardrail",
  "action": "deactivate",
  "name": "No competitor mentions",
  "projects": 3,
  "counts": { "created": 0, "updated": 2, "unchanged": 1, "skipped": 0, "limit_reached": 0, "not_found": 0, "deleted": 0, "failed": 0 },
  "results": [
    { "project_id": "3f6c2a8e-91d4-4b7a-a5e2-6d0c8b1f4e27", "status": "updated", "id": "9c4e7a2b-58d1-4f6a-b3e0-2d8f1c6a9b74", "rows": 1 },
    { "project_id": "7a1d5e9c-2b48-4f03-8e6a-c9d2f0b7a415", "status": "updated", "id": "1e8b3d6f-4a92-4c7e-8b15-f6a0d3c9e271", "rows": 1 },
    { "project_id": "c8b2f6d4-0e37-4a95-9c1d-5b7e3a2f8d06", "status": "unchanged", "id": "6f2a9c1e-7d34-4b8a-a0e6-9e4c1b5d7f32", "rows": 1 }
  ]
}
DELETE/api/v1/guardrails#

Remove by name

Removes the guardrail with that name from every project in scope that has it. Send ?name=…&project_ids=… or the same two fields as a JSON body (a long selection never has to fit in a URL). Same call at /api/v1/skills.

Authentication

Bearer <api_key> — Admin key.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "project_ids": "uuid[]"
}
Fields2Expand
name
stringrequired
query or JSON body
project_ids
uuid[]optional
comma-separated in the query

Response Schema

JSON type shapeExpand
{
  "object": "'bulk_result'",
  "action": "'remove'",
  "counts": "{ … }",
  "results": "[{ project_id, status, rows? }]"
}
Fields4Expand
object
'bulk_result'
action
'remove'
counts
{ … }
results
[{ project_id, status, rows? }]

Code Examples

curl -X DELETE "$BASE/api/v1/guardrails?name=No%20competitor%20mentions" -H "Authorization: Bearer $ADMIN_KEY"
{
  "object": "bulk_result",
  "kind": "guardrail",
  "action": "remove",
  "name": "No competitor mentions",
  "projects": 4,
  "counts": { "created": 0, "updated": 0, "unchanged": 0, "skipped": 0, "limit_reached": 0, "not_found": 1, "deleted": 3, "failed": 0 },
  "results": [
    { "project_id": "3f6c2a8e-91d4-4b7a-a5e2-6d0c8b1f4e27", "status": "deleted", "id": "9c4e7a2b-58d1-4f6a-b3e0-2d8f1c6a9b74", "rows": 1 },
    { "project_id": "7a1d5e9c-2b48-4f03-8e6a-c9d2f0b7a415", "status": "deleted", "id": "1e8b3d6f-4a92-4c7e-8b15-f6a0d3c9e271", "rows": 1 },
    { "project_id": "c8b2f6d4-0e37-4a95-9c1d-5b7e3a2f8d06", "status": "deleted", "id": "6f2a9c1e-7d34-4b8a-a0e6-9e4c1b5d7f32", "rows": 1 },
    { "project_id": "0d9e4b7a-3c61-4e28-b5f9-8a2c6e1d4b93", "status": "not_found" }
  ]
}
Reference · 6 endpoints

Payments

Collect payments from your end-clients into ainvented's Stripe account. By default the equivalent USD amount is credited to your user balance; optionally set credit_target: "project_budget"to credit a project budget instead. USD only. A refund (full or partial) or a lost chargeback takes the credit it paid for back from where it landed — your balance, or the project's paid funds and the cap the payment raised (what the project had already spent of it is charged to your balance, like any spend beyond the paid funds); an open chargeback holds it until it is decided. Card payments ask the card's bank to authenticate the holder (3D Secure): confirm with Stripe.js (confirmPayment / confirmSetup), which shows the bank's step. You can also configure per-project auto-recharge(below) to top a project budget up automatically when it runs low.

In this section
  1. POSTCreate a payment/api/v1/projects/{projectId}/payments
  2. GETList payments/api/v1/projects/{projectId}/payments
  3. GETRead a payment/api/v1/projects/{projectId}/payments/{paymentId}
  4. POSTSave a card/api/v1/projects/{projectId}/payment-methods
  5. GETList saved cards/api/v1/projects/{projectId}/payment-methods
  6. POSTAuto-reload/api/v1/projects/{projectId}/auto-recharge
  7. GuideWebhook events

Credit model — your balance and your projects' money

Your user balance and the money paid into each project are kept apart. A project_budget payment funds only that project (it does not raise your user balance). A project with a budget is self-metered: its budget_cents is its spending cap, and its AI usage first spends what was paid into it (budget.credited_cents). Raising the cap adds no money: spend beyond what was paid in, up to the cap, is charged call by call to your user balance (budget.paid_from_balance_cents), and the project is refused (HTTP 402) when the cap is reached or your balance is empty — the error's message says which. Check it any time via GET /api/v1/projects/{projectId}/balance:can_spend answers whether the next call passes (credited_remaining_cents,draws_from_balance, remaining_cents say why). Budgets & payments apply to every project type (chat, function, canvas) — not chat-only.

Access required

Your account must be approved for payment collection (admin-only opt-in) before you can call these endpoints. To request access, email contact@ainvented.com with the user id you want enrolled and a brief description of your business.

Until approved, every call returns 403 permission_error with code: "payments_not_enabled".

No Stripe key is ever shared with you

The POST endpoint returns a Stripe client_secret — a one-shot token bound to a single PaymentIntent. Your frontend uses it with Stripe.js Elements + ainvented's publishable key.

The client_secret cannot create new charges, refund existing ones, or read any data outside the specific PaymentIntent it's bound to.

POST/api/v1/projects/{projectId}/payments#

Create a payment

Creates a Stripe PaymentIntent on ainvented's Stripe account and returns a client_secret your frontend uses with Stripe.js. Amount is the smallest USD unit (cents) and must be between 50 ($0.50, Stripe's USD floor) and 99,999,999 ($999,999.99). EASIEST INTEGRATION: pass hosted_checkout:true to get a checkout_url instead — redirect your customer to it and you need NO Stripe key at all (not even the publishable key). For amounts ≥ $10, that checkout_url is OUR customer checkout page, which also collects the customer's email (Stripe emails them a receipt for this payment and for every later auto-reload charge), lets them set up auto-reload (toggle ON by default, they can opt out) and return to your site after paying — you don't have to send anything extra. See hosted_checkout + auto_reload below.

Authentication

Bearer <admin_api_key> — must be an account-wide Admin key, must own the project, and your account must be approved for payment collection.

Request Schema

JSON type shapeExpand
{
  "amount_cents": "integer",
  "currency": "\"USD\" (literal; any other value → 400)",
  "description": "string",
  "idempotency_key": "string",
  "credit_target": "\"user_balance\" | \"project_budget\" . Embedded and under-$10 hosted flows default to \"user_balance\". For backward compatibility, the AInvented-hosted $10+ checkout defaults to this path project's \"project_budget\". An explicit value is always honored.",
  "budget_project_id": "uuid",
  "hosted_checkout": "boolean . true → response returns a checkout_url; redirect your customer there. You need NO Stripe key, not even the publishable key. BY DEFAULT (amount_cents ≥ $10) this returns OUR customer checkout page with a required email field (so Stripe receipts the payment and every later auto-reload charge) and an opt-out auto-reload toggle, so your customers can set up auto-reload without you sending anything. success_url/cancel_url are honored on that page as a \"Return to site\" button + a back link (they no longer force the plain Stripe page). The only case that stays on the plain Stripe-hosted page is amount_cents < $10 (too small to carry auto-reload). To keep our page but start the toggle OFF (opt-in), send auto_reload:{enabled:false}; to customize the default amounts, send your own auto_reload object.",
  "success_url": "url",
  "cancel_url": "url",
  "auto_reload": "object"
}
Fields10Expand
amount_cents
integerrequired
50..99,999,999
currency
"USD" (literal; any other value → 400)
description
stringoptional
max 280 chars — shows in Stripe dashboard
idempotency_key
stringoptional
max 255 chars — permanently identifies one payment inside this project. Retrying the same request returns that payment; use a new key for a new payment.
credit_target
"user_balance" | "project_budget" . Embedded and under-$10 hosted flows default to "user_balance". For backward compatibility, the AInvented-hosted $10+ checkout defaults to this path project's "project_budget". An explicit value is always honored.optional
budget_project_id
uuidoptional
the project budget to credit when credit_target="project_budget". Defaults to this path project; a different project must be one you also own (else 403/404).
hosted_checkout
boolean . true → response returns a checkout_url; redirect your customer there. You need NO Stripe key, not even the publishable key. BY DEFAULT (amount_cents ≥ $10) this returns OUR customer checkout page with a required email field (so Stripe receipts the payment and every later auto-reload charge) and an opt-out auto-reload toggle, so your customers can set up auto-reload without you sending anything. success_url/cancel_url are honored on that page as a "Return to site" button + a back link (they no longer force the plain Stripe page). The only case that stays on the plain Stripe-hosted page is amount_cents < $10 (too small to carry auto-reload). To keep our page but start the toggle OFF (opt-in), send auto_reload:{enabled:false}; to customize the default amounts, send your own auto_reload object.optional
default false
success_url
urloptional
hosted_checkout only — where the customer returns after paying. On our checkout page it becomes a "Return to site" button; on the plain Stripe page it is a redirect ({CHECKOUT_SESSION_ID} substituted).
cancel_url
urloptional
hosted_checkout only — a "back" link on our checkout page / a redirect on the Stripe page.
auto_reload
objectoptional
configure project auto-reload alongside this top-up: { enabled?: boolean (defaults true — on the checkout page the auto-reload toggle starts ON so the customer opts OUT; send enabled:false to offer it opt-in), threshold_cents?, recharge_cents?, payment_method_id? }. Behavior depends on the flow: (a) EMBEDDED (no hosted_checkout) → the config is applied server-side immediately and echoed as auto_reload.applied; money/card fields merge onto any existing config. (b) HOSTED_CHECKOUT for $10+ → checkout_url points at OUR customer checkout page: the CUSTOMER reviews/adjusts the settings, the choice is persisted before payment, card saving follows that choice, and auto-reload is applied only after payment succeeds. The email they enter there becomes the receipt address for every off-session recharge, so an auto-reload charge is never silent. The response returns auto_reload {applied:false, pending:true, defaults:{…}}. For the hosted page the top-up and enabled reload amount each have a $10.00 minimum. Omitted on an embedded or under-$10 flow ⇒ no auto_reload key; omitted on a $10+ hosted flow ⇒ the established default-on hosted offer. A config-write failure never reverses a successful payment.

Response Schema

JSON type shapeExpand
{
  "payment_id": "uuid",
  "stripe_client_secret": "pi_*_secret_*",
  "checkout_url": "the page to redirect the customer to (hosted_checkout=true only). For amounts ≥ $10 this is OUR checkout page",
  "checkout_session_id": "cs_*",
  "stripe_payment_intent_id": "pi_*",
  "status": "PaymentStatus enum (REQUIRES_PAYMENT_METHOD, PROCESSING, SUCCEEDED, ...)",
  "amount_cents": "integer",
  "currency": "\"USD\"",
  "description": "string | null",
  "credit_target": "\"user_balance\" | \"project_budget\"",
  "credited_budget_project_id": "uuid | null",
  "created_at": "ISO timestamp",
  "idempotent_replay": "boolean",
  "auto_reload": "object | absent"
}
Fields14Expand
payment_id
uuid
stripe_client_secret
pi_*_secret_*
one-shot, bound to this PaymentIntent. (embedded flow only; absent when hosted_checkout=true)
checkout_url
the page to redirect the customer to (hosted_checkout=true only). For amounts ≥ $10 this is OUR checkout page
https://<app>/checkout/<token> (auto-reload + Return-to-site); for < $10 it is a Stripe-hosted https://checkout.stripe.com/… page.
checkout_session_id
cs_*
the Stripe Checkout Session id (hosted_checkout=true only)
stripe_payment_intent_id
pi_*
the Stripe PI id
status
PaymentStatus enum (REQUIRES_PAYMENT_METHOD, PROCESSING, SUCCEEDED, ...)
amount_cents
integer
currency
"USD"
description
string | null
credit_target
"user_balance" | "project_budget"
where the payment will be credited on success
credited_budget_project_id
uuid | null
the funded project budget (null for user_balance)
created_at
ISO timestamp
idempotent_replay
boolean
true when this request replayed an existing payment
auto_reload
object | absent
present only when you sent auto_reload. Embedded flow: { applied: boolean, config?: {…}, error?: {…} } (applied=false = payment succeeded but config not written, explicit). Hosted-checkout flow: { applied:false, pending:true, defaults:{…} } — the customer sets it on the checkout_url page and it is applied on payment completion.

Code Examples

Easiest integration: get a checkout_url and redirect your customer. For $10+ they land on OUR checkout page — enter an email (Stripe receipts every charge to it), pay + (by default) opt into auto-reload — then a "Return to site" button sends them to success_url. You send nothing extra; you never touch Stripe.

curl -X POST $BASE/api/v1/projects/$PID/payments \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount_cents": 5000,
    "currency": "USD",
    "credit_target": "project_budget",
    "hosted_checkout": true,
    "success_url": "https://your-app.com/thanks",
    "cancel_url": "https://your-app.com/cart"
  }'
# → { "payment_id": "...",
#     "checkout_url": "https://ainvented.com/checkout/<token>",   # OUR page (amount ≥ $10)
#     "auto_reload": { "applied": false, "pending": true,
#                      "defaults": { "enabled": true, "threshold_cents": 1000, "recharge_cents": 2000 } }, ... }
# Redirect your customer to checkout_url. No publishable key, no Stripe.js.
# (Want the toggle OFF by default? add  "auto_reload": {"enabled": false}.
#  Amounts under $10 return a plain Stripe checkout_url with no auto-reload.)

Create a $50.00 payment, then your frontend redeems the client_secret with Stripe.js Elements + your publishable key.

curl -X POST $BASE/api/v1/projects/$PID/payments \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount_cents": 5000,
    "currency": "USD",
    "description": "Order #12345 — Acme Co.",
    "idempotency_key": "order-12345"
  }'

When your account is not yet approved for payment collection.

# Response — 403 Forbidden
# {
#   "error": {
#     "message": "This account is not approved for payment collection. Contact ainvented at contact@ainvented.com to request access to the payments endpoints.",
#     "type": "permission_error",
#     "code": "payments_not_enabled"
#   }
# }
#
# To request access, email contact@ainvented.com with:
#   - your ainvented user id
#   - a brief description of your business
#   - the project id you want to charge from
# Response — 400 Bad Request
# {
#   "error": {
#     "message": "Invalid literal value, expected \"USD\"",
#     "type": "invalid_request_error",
#     "param": "currency"
#   }
# }

The same idempotency_key was used for a different flow, amount, description, credit destination, hosted URL, or auto-reload choice. Mint a fresh key for a new payment, or resend the original request to receive it as a replay.

# Response — 400 Bad Request
# {
#   "error": {
#     "message": "idempotency_key was used for a different payment request. Use a fresh key or resend the original request.",
#     "type": "invalid_request_error",
#     "param": "idempotency_key",
#     "code": "idempotency_key_reused"
#   }
# }

The project was deleted, so it cannot take new payments.

# Response — 403 Forbidden
# {
#   "error": {
#     "message": "Project is disabled",
#     "type": "permission_error",
#     "code": "project_disabled"
#   }
# }

Stripe was unreachable, returned a 5xx, or rejected the request. Safe to retry with the same idempotency_key.

# Response — 502 Bad Gateway
# {
#   "error": {
#     "message": "Payment provider error — please retry",
#     "type": "payment_provider_error"
#   }
# }

Your frontend mounts Stripe Elements with the client_secret + ainvented's publishable key. No Stripe secret key is ever in the browser.

const stripe = Stripe('pk_live_AINVENTED_PUBLISHABLE_KEY');
const elements = stripe.elements({ clientSecret });
elements.create('payment').mount('#payment-element');
document.querySelector('#submit').addEventListener('click', async () => {
  const { error } = await stripe.confirmPayment({
    elements,
    confirmParams: { return_url: 'https://your-site.com/return' },
    redirect: 'if_required',
  });
  if (error) console.error(error.message);
});
GET/api/v1/projects/{projectId}/payments#

List payments for a project

Returns payments ordered by created_at DESC. Supports pagination + status / date filters.

Authentication

Bearer <api_key> — must own the project AND your account must be approved for payment collection.

Request Schema

JSON type shapeExpand
{
  "query.status": "optional PaymentStatus enum (REQUIRES_PAYMENT_METHOD|PROCESSING|REQUIRES_ACTION|SUCCEEDED|FAILED|CANCELED|REFUNDED)",
  "query.limit": "integer 1..200 (default 20)",
  "query.offset": "integer ≥ 0 (default 0)",
  "query.from": "ISO timestamp (inclusive)",
  "query.to": "ISO timestamp (exclusive)"
}
Fields5Expand
query.status
optional PaymentStatus enum (REQUIRES_PAYMENT_METHOD|PROCESSING|REQUIRES_ACTION|SUCCEEDED|FAILED|CANCELED|REFUNDED)
query.limit
integer 1..200 (default 20)
query.offset
integer ≥ 0 (default 0)
query.from
ISO timestamp (inclusive)
query.to
ISO timestamp (exclusive)

Response Schema

JSON type shapeExpand
{
  "data": [
    {
      "payment_id": "uuid",
      "amount_cents": "integer",
      "amount_received_cents": "integer (0 until succeeded)",
      "currency": "\"USD\"",
      "status": "PaymentStatus enum",
      "description": "string | null",
      "credit_target": "\"user_balance\" | \"project_budget\"",
      "credited_budget_project_id": "uuid | null",
      "stripe_payment_intent_id": "string",
      "error_code": "string | null",
      "error_message": "string | null",
      "created_at": "ISO",
      "paid_at": "ISO | null",
      "refunded_at": "ISO | null"
    }
  ],
  "page": {
    "limit": "integer",
    "offset": "integer",
    "has_more": "boolean"
  }
}
Fields19Expand
data
array
array — fields below
payment_id
uuid
amount_cents
integer
amount_received_cents
integer (0 until succeeded)
currency
"USD"
status
PaymentStatus enum
description
string | null
credit_target
"user_balance" | "project_budget"
credited_budget_project_id
uuid | null
the funded project budget
stripe_payment_intent_id
string
error_code
string | null
error_message
string | null
created_at
ISO
paid_at
ISO | null
refunded_at
ISO | null
page
object
object — fields below
limit
integer
offset
integer
has_more
boolean

Code Examples

curl "$BASE/api/v1/projects/$PID/payments?status=SUCCEEDED&limit=50" -H "Authorization: Bearer $API_KEY"
GET/api/v1/projects/{projectId}/payments/{paymentId}#

Read a single payment

Returns the full payment shape. Returns 404 if the payment is not in this project (cross-project lookups are not allowed).

Authentication

Bearer <api_key> — must own the project AND your account must be approved for payment collection.

Response Schema

JSON type shapeExpand
{
  "payment_id": "uuid",
  "project_id": "uuid",
  "amount_cents": "integer",
  "amount_received_cents": "integer",
  "currency": "\"USD\"",
  "status": "PaymentStatus enum",
  "description": "string | null",
  "stripe_payment_intent_id": "string",
  "error_code": "string | null",
  "error_message": "string | null",
  "created_at": "ISO",
  "paid_at": "ISO | null",
  "refunded_at": "ISO | null"
}
Fields13Expand
payment_id
uuid
project_id
uuid
amount_cents
integer
amount_received_cents
integer
currency
"USD"
status
PaymentStatus enum
description
string | null
stripe_payment_intent_id
string
error_code
string | null
error_message
string | null
created_at
ISO
paid_at
ISO | null
refunded_at
ISO | null

Code Examples

curl "$BASE/api/v1/projects/$PID/payments/$PMT_ID" -H "Authorization: Bearer $API_KEY"

You never need a Stripe key

ainvented's Stripe secret key stays on our servers — you never see or handle it. Easiest path (zero Stripe keys): pass hosted_checkout: true to/payments or/payment-methods and you get back acheckout_url — just redirect your customer there. For a $10+ payment it's our checkout page (the customer enters an email for Stripe receipts, can set up auto-reload, and returns to your site); smaller payments and the card-save flow use Stripe's hosted page. Either way you need no Stripe key at all, not even the publishable key. Prefer to stay on your own page? Use the embedded flow instead: confirm the returnedstripe_client_secret client-side with your public publishable key. Everything is authorized with your ainvented API key only.

POST/api/v1/projects/{projectId}/payment-methods#

Save a card (SetupIntent or hosted checkout)

Starts the save-card flow so a card can later back project auto-recharge. Default (embedded): ainvented creates a Stripe customer + SetupIntent server-side and returns a client_secret you confirm with Stripe.js + the PUBLIC publishable key. EASIEST: pass hosted_checkout:true to get a Stripe-hosted checkout_url (setup-mode) — redirect your customer there and you need NO Stripe key at all. Either way the saved pm_… attaches to your customer and is reusable across all your projects. You never touch ainvented's Stripe secret key.

Authentication

Bearer <api_key> — must own the project AND your account must be approved for payment collection.

Request Schema

JSON type shapeExpand
{
  "hosted_checkout": "boolean . true → returns a Stripe-hosted checkout_url (no client_secret, no publishable key needed).",
  "success_url": "url",
  "cancel_url": "url"
}
Fields3Expand
hosted_checkout
boolean . true → returns a Stripe-hosted checkout_url (no client_secret, no publishable key needed).optional
default false
success_url
urloptional
hosted_checkout only — redirect after the card is saved.
cancel_url
urloptional
hosted_checkout only — redirect on cancel.

Response Schema

JSON type shapeExpand
{
  "client_secret": "string",
  "checkout_url": "https://checkout.stripe.com/…",
  "customer_id": "string",
  "publishable_key": "string | null"
}
Fields4Expand
client_secret
string
embedded flow: confirm client-side with Stripe.js + publishable key (absent when hosted_checkout=true)
checkout_url
https://checkout.stripe.com/…
hosted flow: redirect your customer to save a card (hosted_checkout=true only)
customer_id
string
your ainvented Stripe customer id
publishable_key
string | null
the public pk_… to use for embedded confirmation

Code Examples

Redirect your customer to checkout_url to save a card; it then backs per-project auto-recharge.

curl -X POST "$BASE/api/v1/projects/$PID/payment-methods" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"hosted_checkout": true, "success_url": "https://your-app.com/card-saved"}'
# → { "data": { "checkout_url": "https://checkout.stripe.com/c/pay/cs_...", "customer_id": "cus_..." } }
curl -X POST "$BASE/api/v1/projects/$PID/payment-methods" -H "Authorization: Bearer $API_KEY"
GET/api/v1/projects/{projectId}/payment-methods#

List saved cards

Returns the cards saved on your ainvented Stripe customer (so you can pick a pm_… for auto-recharge). Returns [] if you have not saved a card yet.

Authentication

Bearer <api_key> — must own the project AND be approved for payment collection.

Response Schema

JSON type shapeExpand
{
  "id": "string (pm_…)",
  "brand": "string | null",
  "last4": "string | null",
  "exp_month": "integer | null",
  "exp_year": "integer | null"
}
Fields5Expand
id
string (pm_…)
brand
string | null
last4
string | null
exp_month
integer | null
exp_year
integer | null

Code Examples

curl "$BASE/api/v1/projects/$PID/payment-methods" -H "Authorization: Bearer $API_KEY"
POST/api/v1/projects/{projectId}/auto-recharge#

Project auto-reload (create / get / update / disable)

Configure automatic top-up (auto-reload) of a PROJECT BUDGET. When the project’s remaining budget (budget_cents − consumed_cents) drops below threshold_cents, ainvented charges your saved card off-session for recharge_cents and credits the project budget. Four verbs: POST create/enable/partial-patch (enabled required; money/card fields merge onto any existing config; 201 new, 200 update); PUT upsert (full OR partial; money fields optional and merged; 200); GET returns the config (or null); DELETE turns it off (active=false). A lightweight toggle is just a POST with enabled=false or enabled=true. The payment_method_id (pm_…) must already be saved via POST /payment-methods. recharge_cents must be ≥ threshold_cents, and enabling requires a saved card. Each recharge is recorded as a project payment (credit_target=project_budget), is charge-idempotent per 60s window, and fires no AI call. A declined card is not hammered: after two straight declines automatic recharges pause and the card is tried again at most once every 72 h (12 failed attempts in 30 days at most); when the bank asks not to retry the card they switch off after the second attempt, and when Link needs the customer to verify their account or the bank wants the cardholder to confirm the payment (3-D Secure) they are tried once more three days later, then switched off. An attempt the payment processor itself could not answer (error_code stripe_unavailable: a network error, an outage or a rate limit on its side) is not the card’s: it counts toward none of these limits, notifies nobody, and the next check tries again. Saving the config (a new card, or the same settings again) starts afresh — except switching it back on with the very card it was switched off for when the bank asked not to retry it or wants the cardholder to confirm it: that is refused (400 card_needs_replacing), as the next charge would only be declined again; choose a different payment_method_id or have your customer pay a new payment link. Every answer carries the state: status, status_reason, retry_after.

Authentication

Bearer <admin api_key> — must own the project AND be approved for payment collection. (Admin key required; project-scoped keys get 403 admin_key_required.)

Request Schema

JSON type shapeExpand
{
  "enabled": "boolean (POST: required",
  "threshold_cents": "integer",
  "recharge_cents": "integer (optional*, 1000..99,999,999",
  "payment_method_id": "string"
}
Fields4Expand
enabled
boolean (POST: required
the on/off toggle. PUT: optional, defaults true)
threshold_cents
integeroptional
0..99,999,999 — recharge when remaining budget falls below this. Merges onto the existing config when omitted.
recharge_cents
integer (optional*, 1000..99,999,999
minimum $10.00) — amount charged + credited on each recharge. *Required to persist a config; must be ≥ threshold_cents. Merges when omitted.
payment_method_id
stringoptional
*, pm_… — saved Stripe payment method. *Required to enable. Merges when omitted.

Response Schema

JSON type shapeExpand
{
  "project_id": "uuid",
  "threshold_cents": "integer",
  "recharge_cents": "integer",
  "active": "boolean",
  "payment_method_id": "string | null",
  "last_triggered_at": "ISO | null",
  "updated_at": "ISO | null",
  "status": "'active' | 'paused' | 'stopped' | 'inactive'",
  "status_reason": "'repeated_declines' | 'attempt_limit_reached' | 'do_not_try_again' | 'link_additional_verification_required' | 'authentication_required' | null",
  "retry_after": "ISO | null",
  "status_since": "ISO | null",
  "consecutive_failures": "integer"
}
Fields12Expand
project_id
uuid
threshold_cents
integer
recharge_cents
integer
active
boolean
payment_method_id
string | null
last_triggered_at
ISO | null
updated_at
ISO | null
status
'active' | 'paused' | 'stopped' | 'inactive'
paused: on, but held after declines (until retry_after) or waiting for the last try after a verification or confirmation request; stopped: switched off after the card's bank or Link refused it (status_reason says why), on the card the config still holds; inactive: off by choice
status_reason
'repeated_declines' | 'attempt_limit_reached' | 'do_not_try_again' | 'link_additional_verification_required' | 'authentication_required' | null
the last three are the error_code of the project's failed payments
retry_after
ISO | null
paused: no automatic attempt before this time (null once the card's 30-day attempts are spent)
status_since
ISO | null
paused: the latest decline; stopped: when it was switched off
consecutive_failures
integer
straight failed attempts on the current card

Code Examples

curl -X POST "$BASE/api/v1/projects/$PID/auto-recharge" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"enabled": true, "threshold_cents": 1000, "recharge_cents": 5000, "payment_method_id": "pm_..."}'
curl -X POST "$BASE/api/v1/projects/$PID/auto-recharge" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"enabled": false}'
curl "$BASE/api/v1/projects/$PID/auto-recharge" -H "Authorization: Bearer $API_KEY"
curl -X DELETE "$BASE/api/v1/projects/$PID/auto-recharge" -H "Authorization: Bearer $API_KEY"
Guide

Webhook events

Subscribe via POST /api/v1/projects/{id}/webhooks with events: ['payment.succeeded', 'payment.failed'] in the body.

  • payment.succeeded — fired once when the PaymentIntent reaches the terminal succeeded state. Payload includes amount_received_cents, paid_at, stripe_payment_intent_id.
  • payment.failed — fired on each failed attempt (Stripe allows retries). Payload includes error_code, error_message.

No DELETE endpoint. Refunds are not supported via API. If you need to refund a customer, use the Stripe dashboard; the row's status will mirror to REFUNDED but your balance is NOT debited (manual reconciliation).

Reference · 22 endpoints

WhatsApp

Attach a customer's own WhatsApp Business account to one of your projects. You call one endpoint, get back a URL, and hand it to your customer — they sign in with Meta and pick their number. Neither you nor they ever type a WhatsApp access token, a phone number ID or a verify token; Ainvented obtains them from Meta server-side and stores them encrypted.

Once connected, a WhatsApp account appears on the project. What happens to the messages it receives depends on the account's mode, chosen when you mint the link: either the project's assistant answers by itself, or — the default for links minted through this API — every message is handed to your application through a webhook and you reply through the API, with nothing generated in between. All of these endpoints are reserved for reseller accounts and take an Admin API key.

In this section
  1. GuideAssistant vs API mode
  2. POSTCreate a connect link/api/v1/projects/{projectId}/whatsapp/connect
  3. GETCheck connect links/api/v1/projects/{projectId}/whatsapp/connect
  4. GETList accounts/api/v1/projects/{projectId}/whatsapp/accounts
  5. GETRead an account/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}
  6. PUTUpdate an account/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}
  7. GETWho wrote in/api/v1/projects/{projectId}/whatsapp/conversations
  8. GETRead messages/api/v1/projects/{projectId}/whatsapp/messages
  9. POSTSend a message/api/v1/projects/{projectId}/whatsapp/messages
  10. GETDownload media/api/v1/projects/{projectId}/whatsapp/media/{mediaId}?account_id={accountId}
  11. GETList templates/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates
  12. POSTCreate a template/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates
  13. POSTUpload a header sample/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates/media
  14. GETRead a template/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates/{templateId}
  15. PUTEdit a template/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates/{templateId}
  16. DELETEDelete a template/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates/{templateId}
  17. POSTRegister a webhook/api/v1/projects/{projectId}/whatsapp/webhooks
  18. GETManage webhooks/api/v1/projects/{projectId}/whatsapp/webhooks
  19. GETTraffic of a project/api/v1/projects/{projectId}/whatsapp/traffic
  20. GETEvery number, all projects/api/v1/whatsapp/accounts
  21. PUTBulk mode / active/api/v1/whatsapp/accounts
  22. GETTraffic, all projects/api/v1/whatsapp/traffic
  23. POSTWebhook on every project/api/v1/whatsapp/webhooks
  24. GuideWebhook payload & signature
  25. GuideWhat your customer sees
Guide

Assistant mode vs API mode

mode: "assistant"mode: "api" (default here)
Who answersThe project's assistant, immediately, from the customer's number. Same behaviour as connecting from the AI Chat view.Your application. Nothing is generated: the message is stored, delivered to your webhooks, and you reply — or not — with POST /whatsapp/messages.
What it costs youEach inbound message is a priced assistant turn on the project, like a chat completion.No tokens are spent on the project for inbound or outbound messages. WhatsApp bills the customer's own account for conversations, as always.
HistoryLives with the chat session; not exposed here.GET /whatsapp/conversations and GET /whatsapp/messages hold every message in both directions, including failed sends.
SwitchingAny time, without reconnecting: PUT /whatsapp/accounts/{accountId} with the new mode. Accounts connected before modes existed are assistants until you switch them.
POST/api/v1/projects/{projectId}/whatsapp/connect#

Create a connect link

Mints a one-shot URL that walks your customer through Meta's Embedded Signup and attaches the resulting WhatsApp Business account to this project. Same shape as hosted checkout: you get a URL and hand it over — no SDK, no Meta app of your own. The link is single-use and expires after 7 days. The account it creates is in API mode unless you ask for an assistant. Send the customer's number with it: the link then finishes even if they close our page early, and they are never asked for it.

Authentication

Bearer <admin_api_key> — must be an account-wide Admin key (no project binding), must own the project, and the account must be a reseller.

Request Schema

JSON type shapeExpand
{
  "connector_name": "string",
  "return_url": "url",
  "mode": "\"api\" | \"assistant\" (optional, default \"assistant\"",
  "phone_number": "string"
}
Fields4Expand
connector_name
stringoptional
max 100 chars — label for the account that gets created. Omit it and the verified business name Meta returns is used instead, which is usually better than anything typed by hand.
return_url
urloptional
where the customer lands after connecting. Must be http or https; other schemes are rejected with 400. Omit it and they stay on a success card.
mode
"api" | "assistant" (optional, default "assistant"
what every connect link did before modes existed, so existing integrations keep working unchanged) — who answers on the connected number. "api": messages go to your webhooks and you reply through this API; "assistant": the project's assistant replies by itself.
phone_number
stringoptional
recommended — the WhatsApp Business number your customer is about to connect, with its country code ("+34 600 111 222"; spaces, dashes and dots are ignored; 8 to 15 digits). Meta reports a shared account, never which customer shared it: the number is how we tie that share to this link, so the connection completes even if the customer closes our page early, however many customers are connecting at once, and they are never asked for their number's last digits. Omit it and our page asks the customer for the number before sending them to Meta (recommended there too, not required).

Response Schema

JSON type shapeExpand
{
  "connect_url": "the URL to hand your customer",
  "connect_token": "the token embedded in that URL; use it to correlate with the list endpoint",
  "project_id": "uuid",
  "status": "\"pending\" on creation",
  "connector_name": "string | null",
  "return_url": "string | null",
  "mode": "\"api\" | \"assistant\"",
  "phone_number": "string | null",
  "expires_at": "ISO timestamp"
}
Fields9Expand
connect_url
the URL to hand your customer
https://<app>/connect/whatsapp/<token>
connect_token
the token embedded in that URL; use it to correlate with the list endpoint
project_id
uuid
the project the WhatsApp account will be attached to
status
"pending" on creation
connector_name
string | null
echoed back
return_url
string | null
echoed back
mode
"api" | "assistant"
the mode the account will be created in
phone_number
string | null
the number the link expects, normalised to E.164 ("+34600111222"), or null
expires_at
ISO timestamp
after this the link is dead and you must mint another

Code Examples

Send the returned connect_url to your customer however you like: an email, a button in your own dashboard, a QR code. It requires no Ainvented login on their side. Pass their number when you know it.

curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/connect" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "connector_name": "Acme Support",
    "phone_number": "+34 600 111 222",
    "return_url": "https://acme.example/settings/whatsapp?done=1"
  }'
# → { "connect_url": "https://ainvented.com/connect/whatsapp/DlhaNJ_Jyaf...",
#     "connect_token": "DlhaNJ_Jyaf...",
#     "status": "pending",
#     "phone_number": "+34600111222",
#     "expires_at": "2026-08-31T20:17:38.262Z" }

Details

Errors

  • 403 admin_key_required — the key is bound to a project. Everything under /v1/projects/** is account management and needs an Admin key.
  • 403 whatsapp_not_enabled — the account is not approved for the WhatsApp endpoints. Every route under /whatsapp/ returns this for a non-reseller account.
  • 403 project_disabled — the project was deleted.
  • 400 — bad project id, a return_url that is not http(s), or a mode other than the two above.
  • 400 invalid_phone_number — a phone_number that is not a number with its country code (8 to 15 digits). Nothing is minted.
  • 503 whatsapp_not_configured — WhatsApp onboarding is not switched on for this deployment. Never a client bug; retry later.
GET/api/v1/projects/{projectId}/whatsapp/connect#

Check connect links

Lists the connect links issued for this project, newest first, so you can tell whether a customer finished. Poll it after handing over a link, or read it on demand when your customer returns to your app.

Authentication

Bearer <admin_api_key> — same requirements as the POST.

Request Schema

JSON type shapeExpand
{
  "status": "\"pending\" | \"completed\" | \"failed\"",
  "limit": "integer",
  "offset": "integer"
}
Fields3Expand
status
"pending" | "completed" | "failed"optional
query — filter
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].connect_token": "the token from the POST response",
  "data[].status": "\"pending\" (issued, unused) | \"completed\" (connected) | \"failed\" (an attempt failed; the link still works and they can retry) | \"expired\" (past expires_at)",
  "data[].connector_id": "uuid | null",
  "data[].connector_name": "string | null",
  "data[].mode": "\"api\" | \"assistant\"",
  "data[].phone_number": "string | null",
  "data[].error_message": "string | null",
  "data[].created_at": "ISO timestamp",
  "data[].expires_at": "ISO timestamp",
  "data[].completed_at": "ISO timestamp | null",
  "page": "{ limit, offset, has_more }"
}
Fields11Expand
data[].connect_token
the token from the POST response
correlate on this
data[].status
"pending" (issued, unused) | "completed" (connected) | "failed" (an attempt failed; the link still works and they can retry) | "expired" (past expires_at)
data[].connector_id
uuid | null
populated once status is "completed"; this is the WhatsApp account now live on the project (its account_id everywhere below)
data[].connector_name
string | null
data[].mode
"api" | "assistant"
the mode the link was minted with; links minted before modes existed read as "assistant"
data[].phone_number
string | null
the number the link expects (E.164): what you sent, or what the customer typed on our page; null for a link that carries none
data[].error_message
string | null
why the last attempt failed
data[].created_at
ISO timestamp
data[].expires_at
ISO timestamp
data[].completed_at
ISO timestamp | null
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/whatsapp/connect?status=completed" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

The listing never returns connect_url again

A link is a bearer capability — whoever holds it can attach a WhatsApp account to that project — so it is issued once and never re-exposed. To get another, POST again.

GET/api/v1/projects/{projectId}/whatsapp/accounts#

List connected accounts

The WhatsApp accounts attached to this project, with their mode, how many people have written to each and how many of your webhooks fire for them. Inactive accounts are hidden unless asked for.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account. Same for every endpoint below.

Request Schema

JSON type shapeExpand
{
  "mode": "\"api\" | \"assistant\"",
  "include_inactive": "true"
}
Fields2Expand
mode
"api" | "assistant"optional
query — only accounts in that mode
include_inactive
trueoptional
query — also list deactivated accounts

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].name": "string",
  "data[].mode": "\"api\" | \"assistant\"",
  "data[].display_phone_number": "string | null",
  "data[].verified_name": "string | null",
  "data[].phone_number_id": "string | null",
  "data[].business_account_id": "string | null",
  "data[].onboarded_via": "\"embedded_signup\" | \"manual\" | null",
  "data[].is_active": "boolean",
  "data[].token_expires_at": "ISO timestamp | null",
  "data[].needs_reconnect": "boolean",
  "data[].connected_at": "ISO timestamp",
  "data[].conversation_count": "integer",
  "data[].last_inbound_at": "ISO timestamp | null",
  "data[].webhook_count": "integer"
}
Fields15Expand
data[].id
uuid
the account_id used by every other endpoint
data[].name
string
data[].mode
"api" | "assistant"
data[].display_phone_number
string | null
the number as people see it
data[].verified_name
string | null
the business name WhatsApp verified
data[].phone_number_id
string | null
data[].business_account_id
string | null
data[].onboarded_via
"embedded_signup" | "manual" | null
data[].is_active
boolean
data[].token_expires_at
ISO timestamp | null
null means the authorization does not expire
data[].needs_reconnect
boolean
true once the authorization has expired; mint a new connect link
data[].connected_at
ISO timestamp
data[].conversation_count
integer
people who have written to this account (API mode only)
data[].last_inbound_at
ISO timestamp | null
data[].webhook_count
integer
your active webhooks that fire for this account

Code Examples

curl "$BASE/api/v1/projects/$PID/whatsapp/accounts?mode=api" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}#

Read an account

One connected account with the same fields as the listing. 404 account_not_found for an account of another project — an account id never resolves across projects.

Authentication

Bearer <admin_api_key>

Response Schema

JSON type shapeExpand
{
  "…": "the same object as one row of the listing"
}
Fields1Expand
…
the same object as one row of the listing

Code Examples

curl "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"
PUT/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}#

Update an account

Rename an account, switch its mode, deactivate it, or give a manually configured account its WhatsApp Business Account id. Switching an account connected from the AI Chat view — or before modes existed — to API mode is how it stops answering by itself and starts reaching your webhooks; the customer does not reconnect. Every change is written to the project's audit log.

Authentication

Bearer <admin_api_key>

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "mode": "\"api\" | \"assistant\"",
  "is_active": "boolean",
  "business_account_id": "string"
}
Fields4Expand
name
stringoptional
1..100 chars
mode
"api" | "assistant"optional
is_active
booleanoptional
false stops both directions: inbound messages are ignored and sends are refused with 409 account_inactive
business_account_id
stringoptional
numeric — the WhatsApp Business Account id of an account that was connected by hand (phone number id + token), which the template endpoints need. Settable once; stored only after WhatsApp confirms the account's own token can read that business account. Accounts connected through a connect link already carry it

Response Schema

JSON type shapeExpand
{
  "…": "the updated account, same shape as the listing"
}
Fields1Expand
…
the updated account, same shape as the listing

Code Examples

curl -X PUT "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "api" }'

Details

Errors

  • 400 — nothing to update, a mode other than the two, or a business_account_id that is not numeric.
  • 400 business_account_unverified — WhatsApp does not let the account's token read that business account; nothing is stored. Check the id in WhatsApp Manager, or reconnect the number through a connect link.
  • 409 business_account_already_set — the account already carries its business account id (every connect-link account does).
  • 404 account_not_found — not an account of this project.
  • 403 project_disabled — the project was deleted.
GET/api/v1/projects/{projectId}/whatsapp/conversations#

Who wrote in

One row per phone that has written to one of the project's API-mode accounts, most recent message first. A customer who writes to two of your numbers is two conversations. This is also the list of phones you may send free-form messages to.

Authentication

Bearer <admin_api_key>

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "phone": "string",
  "since": "ISO datetime",
  "limit": "integer",
  "offset": "integer"
}
Fields5Expand
account_id
uuidoptional
query — one account only; 404 if it is not on this project
phone
stringoptional
query — one customer, in international format with or without the plus sign
since
ISO datetimeoptional
query — conversations with an inbound message at or after this moment
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].account_id": "uuid",
  "data[].phone": "string",
  "data[].profile_name": "string | null",
  "data[].first_inbound_at": "ISO timestamp | null",
  "data[].last_inbound_at": "ISO timestamp | null",
  "data[].last_outbound_at": "ISO timestamp | null",
  "data[].inbound_count": "integer",
  "data[].outbound_count": "integer",
  "data[].last_message": "{ direction: \"inbound\" | \"outbound\", preview: string } | null",
  "page": "{ limit, offset, has_more }"
}
Fields11Expand
data[].id
uuid
usable as conversation_id when reading messages
data[].account_id
uuid
data[].phone
string
digits in international format, no plus sign; use it as `to` when replying
data[].profile_name
string | null
the name the customer chose on WhatsApp
data[].first_inbound_at
ISO timestamp | null
data[].last_inbound_at
ISO timestamp | null
data[].last_outbound_at
ISO timestamp | null
data[].inbound_count
integer
data[].outbound_count
integer
successful sends only
data[].last_message
{ direction: "inbound" | "outbound", preview: string } | null
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/whatsapp/conversations?account_id=$ACCOUNT_ID&since=$(date -u +%Y-%m-%dT00:00:00Z)" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/whatsapp/messages#

Read messages

Every message on the project's API-mode accounts, in both directions, newest first: what customers sent, what you sent, and what failed to send. Every inbound message is stored BEFORE any webhook delivery is attempted, so this is your fallback when your endpoint was down — filter on since and order=asc to catch up. GET /whatsapp/messages/{messageId} returns one message with its full payload.

Authentication

Bearer <admin_api_key>

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "conversation_id": "uuid",
  "phone": "string",
  "direction": "\"inbound\" | \"outbound\"",
  "type": "text | image | audio | video | document | sticker | location | contacts | reaction | interactive | button | order | template | unsupported | unknown",
  "status": "received | sent | delivered | read | failed",
  "since": "ISO datetime",
  "until": "ISO datetime",
  "order": "\"desc\" (default) | \"asc\"",
  "include_payload": "true",
  "limit": "integer",
  "offset": "integer"
}
Fields12Expand
account_id
uuidoptional
query
conversation_id
uuidoptional
query
phone
stringoptional
query — messages from or to this customer
direction
"inbound" | "outbound"optional
query
type
text | image | audio | video | document | sticker | location | contacts | reaction | interactive | button | order | template | unsupported | unknownoptional
query
status
received | sent | delivered | read | failedoptional
query
since
ISO datetimeoptional
query — on the moment the message happened on WhatsApp
until
ISO datetimeoptional
query
order
"desc" (default) | "asc"
include_payload
trueoptional
query — include the message exactly as WhatsApp delivered it (inbound) or exactly as it was sent (outbound): the contact cards of a "contacts" message, the coordinates of a "location", the id of the button or row pressed in an "interactive" reply, an "order", a "reaction"…
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].account_id": "uuid",
  "data[].conversation_id": "uuid",
  "data[].direction": "\"inbound\" | \"outbound\"",
  "data[].wa_message_id": "string | null",
  "data[].from": "string",
  "data[].to": "string",
  "data[].type": "string",
  "data[].text": "string | null",
  "data[].media": "{ id, mime_type, sha256, filename?, voice?, animated? } | null",
  "data[].status": "\"received\" for inbound; \"sent\" → \"delivered\" → \"read\", or \"failed\", for outbound",
  "data[].error": "{ code, message } | null",
  "data[].sent_at": "ISO timestamp",
  "data[].delivered_at": "ISO timestamp | null",
  "data[].read_at": "ISO timestamp | null",
  "data[].webhook": "{ status: \"none\" | \"pending\" | \"delivered\" | \"failed\", delivered_at } for inbound messages; null for outbound",
  "data[].api_key_id": "uuid | null",
  "data[].created_at": "ISO timestamp",
  "data[].referral": "object | null",
  "data[].payload": "object",
  "page": "{ limit, offset, has_more }"
}
Fields21Expand
data[].id
uuid
data[].account_id
uuid
data[].conversation_id
uuid
data[].direction
"inbound" | "outbound"
data[].wa_message_id
string | null
WhatsApp's own id; pass it as reply_to to quote the message
data[].from
string
phone digits
data[].to
string
phone digits
data[].type
string
see the type filter
data[].text
string | null
body of a text, caption of a media message, title of a pressed button or list row, name of a location, emoji of a reaction, names on a contact card. A summary: the whole content of those types is in payload
data[].media
{ id, mime_type, sha256, filename?, voice?, animated? } | null
id is what GET /whatsapp/media/{id} takes
data[].status
"received" for inbound; "sent" → "delivered" → "read", or "failed", for outbound
data[].error
{ code, message } | null
why an outbound message failed
data[].sent_at
ISO timestamp
when it happened on WhatsApp
data[].delivered_at
ISO timestamp | null
data[].read_at
ISO timestamp | null
data[].webhook
{ status: "none" | "pending" | "delivered" | "failed", delivered_at } for inbound messages; null for outbound
data[].api_key_id
uuid | null
the key that sent an outbound message
data[].created_at
ISO timestamp
data[].referral
object | null
when the customer wrote in from a Click-to-WhatsApp ad or the WhatsApp button of a Facebook / Instagram post: source_type ("ad" | "post"), source_id, source_url, headline, body, media_type, image_url or video_url and, for ads, ctwa_clid (the click id to attribute the conversation and the sale in Meta's tools). Exactly as WhatsApp delivered it; null on every other message
data[].payload
object
only with include_payload=true (always present in webhook events)
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/whatsapp/messages?direction=inbound&since=2026-09-03T08:00:00Z&order=asc&limit=200" \
  -H "Authorization: Bearer $ADMIN_KEY"

A "contacts" message: text carries the names, payload the phones (wa_id included), emails, organisation and addresses exactly as WhatsApp sent them. "location", "interactive", "button", "reaction" and "order" work the same way — the type-specific block sits in payload under the type's own key.

{
  "id": "…", "direction": "inbound", "type": "contacts", "text": "Ana Pérez",
  "media": null, "referral": null,
  "payload": {
    "from": "573156399415", "id": "wamid.HBgL…", "timestamp": "1789246740", "type": "contacts",
    "contacts": [{
      "name": { "formatted_name": "Ana Pérez", "first_name": "Ana", "last_name": "Pérez" },
      "phones": [{ "phone": "+57 315 639 9415", "type": "CELL", "wa_id": "573156399415" }],
      "emails": [{ "email": "ana@acme.example", "type": "WORK" }],
      "org": { "company": "Acme", "title": "Sales" }
    }]
  }
}

referral is present on the first message of a customer who tapped a Click-to-WhatsApp ad or the WhatsApp button of a post. ctwa_clid is the click id you hand to Meta's Conversions API to attribute the sale.

{
  "id": "…", "direction": "inbound", "type": "text", "text": "¡Hola! Quiero más información",
  "referral": {
    "source_url": "https://fb.me/2XyZ…", "source_id": "120212345678901234", "source_type": "ad",
    "headline": "Varimarket Shop", "body": "Tus pasteles nunca volverán a verse simples…",
    "media_type": "image", "image_url": "https://scontent.xx.fbcdn.net/…", "ctwa_clid": "ARAkGf…"
  }
}
POST/api/v1/projects/{projectId}/whatsapp/messages#

Send a message

Sends a message from one of the project's API-mode accounts. A free-form message (text, media or interactive) can only go to a phone that has written to that account, and WhatsApp itself refuses it once 24 hours have passed since the customer's last message. A template message may go to any phone and opens the conversation. The message is stored either way — a refused send is a message with status "failed" and its reason — and nothing is generated on your behalf: you decide every word. Interactive messages — reply buttons, a pick-one list, a call-to-action link, a request for the customer's location — take the interactive object in the shape WhatsApp itself uses; the customer's answer arrives as an inbound message of type "interactive" whose payload carries the id of the button or row they pressed.

Authentication

Bearer <admin_api_key> — also subject to the key's rate limit (429 rate_limit_exceeded with Retry-After).

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "to": "string",
  "type": "\"text\" (default) | \"image\" | \"audio\" | \"video\" | \"document\" | \"sticker\" | \"template\" | \"interactive\"",
  "text": "string (max 4096)",
  "media_url": "https url",
  "filename": "string",
  "template": "{ name, language, components? }",
  "interactive": "{ type, header?, body, footer?, action }",
  "reply_to": "string",
  "preview_url": "boolean"
}
Fields10Expand
account_id
uuid
the account to send from; must be active and in API mode
to
string
recipient in international format; the plus sign and spaces are optional
type
"text" (default) | "image" | "audio" | "video" | "document" | "sticker" | "template" | "interactive"
text
string (max 4096)
the body of a text message; the caption of an image, video or document
media_url
https url
where WhatsApp fetches the media from; required for the media types
filename
stringoptional
document name shown to the recipient
template
{ name, language, components? }
required for type "template"; an approved template of the customer's WhatsApp Business account
interactive
{ type, header?, body, footer?, action }
required for type "interactive". type: "button" (action.buttons: 1-3 × { type: "reply", reply: { id ≤256, title ≤20 } }, unique ids), "list" (action.button ≤20 — the label that opens the list — and action.sections: 1-10 × { title?, rows: [{ id ≤200, title ≤24, description? ≤72 }] }, at most 10 rows in all, unique ids), "cta_url" (action: { name: "cta_url", parameters: { display_text ≤20, url } }) or "location_request_message" (action: { name: "send_location" }). body.text ≤1024; footer.text ≤60; header: { type: "text", text ≤60 } — or, for button and cta_url, { type: "image" | "video" | "document", <type>: { link: https url } }
reply_to
stringoptional
wa_message_id of the message being answered; renders as a quoted reply
preview_url
booleanoptional
text only — let WhatsApp render a preview of the first link in the body

Response Schema

JSON type shapeExpand
{
  "…": "the stored outbound message, same shape as a row of GET /whatsapp/messages, status \"sent\", HTTP 201"
}
Fields1Expand
…
the stored outbound message, same shape as a row of GET /whatsapp/messages, status "sent", HTTP 201

Code Examples

curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "to": "+34 600 111 222",
    "text": "Your order 4521 ships tomorrow. Anything else we can help with?",
    "reply_to": "wamid.HBhMMzQ2MDAxMTEyMjIVAgASGBQzQTZDMEE5MDQ1QjE4MDU1RkMyMwA="
  }'
# → 201 { "id": "…", "direction": "outbound", "status": "sent", "wa_message_id": "wamid.…", … }
curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "to": "34600111222",
    "type": "document",
    "media_url": "https://acme.example/invoices/4521.pdf",
    "filename": "invoice-4521.pdf",
    "text": "Here is your invoice."
  }'
curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "to": "34600111222",
    "type": "template",
    "template": { "name": "order_update", "language": "es",
                  "components": [{ "type": "body", "parameters": [{ "type": "text", "text": "4521" }] }] }
  }'

What the customer taps comes back as an inbound message of type "interactive": text is the button's title and payload.interactive.button_reply.id the id you gave it.

curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "to": "34600111222",
    "type": "interactive",
    "interactive": {
      "type": "button",
      "header": { "type": "text", "text": "Pedido 4521" },
      "body": { "text": "Tu pedido está listo. ¿Confirmamos la entrega para mañana?" },
      "footer": { "text": "Acme" },
      "action": { "buttons": [
        { "type": "reply", "reply": { "id": "confirm-4521", "title": "Sí, mañana" } },
        { "type": "reply", "reply": { "id": "reschedule-4521", "title": "Otro día" } }
      ] }
    }
  }'
# → 201 { "type": "interactive", "text": "Tu pedido está listo. ¿Confirmamos la entrega para mañana?", "status": "sent", … }
# later, on your webhook: { "event": "whatsapp.message.received", "data": { "message": { "type": "interactive", "text": "Sí, mañana",
#   "payload": { "interactive": { "type": "button_reply", "button_reply": { "id": "confirm-4521", "title": "Sí, mañana" } }, … } } } }
curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "to": "34600111222",
    "type": "interactive",
    "interactive": {
      "type": "list",
      "body": { "text": "Elige la franja de entrega." },
      "action": { "button": "Ver franjas", "sections": [
        { "title": "Mañana", "rows": [ { "id": "slot-am", "title": "9:00 – 13:00" } ] },
        { "title": "Tarde",  "rows": [ { "id": "slot-pm", "title": "16:00 – 20:00", "description": "Última franja del día" } ] }
      ] }
    }
  }'
# the answer: type "interactive", text "9:00 – 13:00", payload.interactive.list_reply.id "slot-am"
{
  "error": {
    "message": "The 24-hour customer service window for this phone has closed. Send an approved template to reopen the conversation.",
    "type": "api_error",
    "code": "whatsapp_send_failed",
    "details": { "whatsapp_code": 131047, "whatsapp_message": "(#131047) Re-engagement message",
                 "retryable": false, "message_id": "…the failed row, readable in GET /whatsapp/messages…" }
  }
}

Details

Errors

  • 400 — the offending field is named in error.param: a text message without text, a media type without an https media_url, a template type without template, a to that is not a phone; for an interactive message the whole path (interactive.action.buttons.0.reply.title) — a fourth button, a title over 20 characters, an eleventh row, a media header on a list, two rows with the same id — so WhatsApp's own refusal (131009) is never the first you hear of it.
  • 404 conversation_not_found — a free-form message to a phone that never wrote to this account. Send a template instead.
  • 404 account_not_found — not an account of this project.
  • 409 account_not_api_mode — the assistant answers on this account; switch it with the PUT above.
  • 409 account_inactive — deactivated account.
  • 409 account_reauthorization_required — the customer's authorization expired or was revoked. Mint a new connect link and have them reconnect; the account keeps its id and history.
  • 502 whatsapp_send_failed — WhatsApp refused the message; details.whatsapp_code says why and details.retryable whether waiting helps.
  • 502 whatsapp_unreachable — the WhatsApp API did not answer in time. Nothing was sent; retry.
  • 429 rate_limit_exceeded — your key's bucket is empty; honour Retry-After.
GET/api/v1/projects/{projectId}/whatsapp/media/{mediaId}?account_id={accountId}#

Download media

The bytes of an image, audio, video, document or sticker a customer sent. Inbound messages carry media.id; fetching it needs the account's authorization, which never leaves the server, so this endpoint fetches it for you and streams the file back with its content type. Media stays available on WhatsApp for a limited time — download what you need to keep.

Authentication

Bearer <admin_api_key>

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid"
}
Fields1Expand
account_id
uuidrequired
query — the account the message arrived on

Response Schema

JSON type shapeExpand
{
  "body": "the file bytes",
  "Content-Type": "the media's type, e.g. image/jpeg, audio/ogg, application/pdf",
  "Content-Length": "bytes",
  "X-WhatsApp-Media-Sha256": "hex digest reported by WhatsApp, when available"
}
Fields4Expand
body
the file bytes
Content-Type
the media's type, e.g. image/jpeg, audio/ogg, application/pdf
Content-Length
bytes
X-WhatsApp-Media-Sha256
hex digest reported by WhatsApp, when available

Code Examples

curl "$BASE/api/v1/projects/$PID/whatsapp/media/$MEDIA_ID?account_id=$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" -o photo.jpg

Details

Errors

  • 404 media_not_found — unknown id, or the file has expired on WhatsApp.
  • 413 media_too_large — over the size limit (25 MB by default).
  • 409 account_reauthorization_required — the account's authorization is no longer valid.
  • 502 whatsapp_unreachable / whatsapp_media_failed — WhatsApp did not return the file; retry.
GET/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates#

List templates

The message templates of one connected account, read live from its WhatsApp Business Account: name, language, category, review status, components and quality. A template is the only message WhatsApp lets you send to a phone that has not written in, or after the 24-hour window has closed (POST /whatsapp/messages with type "template"), so this is where you check what is approved before sending. Nothing is cached on Ainvented: WhatsApp is the source of truth. Pages are cursor-based — pass next_cursor back as after.

Authentication

Bearer <admin_api_key> — reseller-only, like every route under /whatsapp/. Works for accounts in either mode: templates belong to the business account, not to the way the number answers.

Request Schema

JSON type shapeExpand
{
  "status": "\"APPROVED\" | \"PENDING\" | \"REJECTED\" | \"PAUSED\" | \"DISABLED\" | \"IN_APPEAL\" | \"PENDING_DELETION\" | \"DELETED\" | \"LIMIT_EXCEEDED\"",
  "category": "\"MARKETING\" | \"UTILITY\" | \"AUTHENTICATION\"",
  "language": "string",
  "name": "string",
  "search": "string",
  "limit": "integer 1-100",
  "after": "string"
}
Fields7Expand
status
"APPROVED" | "PENDING" | "REJECTED" | "PAUSED" | "DISABLED" | "IN_APPEAL" | "PENDING_DELETION" | "DELETED" | "LIMIT_EXCEEDED"optional
query, case-insensitive
category
"MARKETING" | "UTILITY" | "AUTHENTICATION"optional
query, case-insensitive
language
stringoptional
query — a WhatsApp language code such as "es" or "en_US"
name
stringoptional
query — exact template name
search
stringoptional
query, max 200 — matches the name or the text of the template
limit
integer 1-100optional
query, default 25
after
stringoptional
query — the next_cursor of the previous page

Response Schema

JSON type shapeExpand
{
  "data[].id": "string",
  "data[].account_id": "uuid",
  "data[].name": "string",
  "data[].language": "string",
  "data[].status": "\"APPROVED\" | \"PENDING\" | \"REJECTED\" | \"PAUSED\" | \"DISABLED\" | \"IN_APPEAL\" | \"PENDING_DELETION\" | \"DELETED\" | \"LIMIT_EXCEEDED\"",
  "data[].category": "\"MARKETING\" | \"UTILITY\" | \"AUTHENTICATION\"",
  "data[].sub_category": "string | null",
  "data[].components": "array",
  "data[].parameter_format": "\"POSITIONAL\" | \"NAMED\" | null",
  "data[].message_send_ttl_seconds": "integer | null",
  "data[].quality": "{ score: \"GREEN\" | \"YELLOW\" | \"RED\" | \"UNKNOWN\", updated_at: ISO timestamp | null, reasons } | null",
  "data[].rejected_reason": "string | null",
  "data[].previous_category": "string | null",
  "data[].correct_category": "string | null",
  "page.limit": "integer",
  "page.cursor": "string | null",
  "page.next_cursor": "string | null",
  "page.has_more": "boolean"
}
Fields18Expand
data[].id
string
WhatsApp's template id; the same id the whatsapp.template.* webhook events carry
data[].account_id
uuid
the account it was read through
data[].name
string
lowercase letters, digits and underscores; what you send with type "template"
data[].language
string
one template name can exist in several languages, each with its own id and status
data[].status
"APPROVED" | "PENDING" | "REJECTED" | "PAUSED" | "DISABLED" | "IN_APPEAL" | "PENDING_DELETION" | "DELETED" | "LIMIT_EXCEEDED"
data[].category
"MARKETING" | "UTILITY" | "AUTHENTICATION"
data[].sub_category
string | null
data[].components
array
the HEADER / BODY / FOOTER / BUTTONS objects exactly as WhatsApp stores them, example values included
data[].parameter_format
"POSITIONAL" | "NAMED" | null
how the variables in the text are written ({{1}} or {{name}})
data[].message_send_ttl_seconds
integer | null
how long WhatsApp keeps trying to deliver a message of this template
data[].quality
{ score: "GREEN" | "YELLOW" | "RED" | "UNKNOWN", updated_at: ISO timestamp | null, reasons } | null
WhatsApp's quality rating, driven by how recipients react
data[].rejected_reason
string | null
why WhatsApp rejected it, when it did
data[].previous_category
string | null
set when WhatsApp re-filed the template under another category
data[].correct_category
string | null
the category WhatsApp thinks it should have
page.limit
integer
page.cursor
string | null
the after you passed
page.next_cursor
string | null
pass it as after for the next page; null on the last one
page.has_more
boolean

Code Examples

Only an APPROVED template can be sent. Filter on it before offering the list to your own users.

curl "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates?status=approved&limit=50" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → { "data": [ { "id": "1011820805234855", "name": "order_update", "language": "es", "status": "APPROVED",
#                 "category": "UTILITY", "components": [ { "type": "BODY", "text": "Hola {{1}}, tu pedido {{2}} sale mañana." } ], … } ],
#     "page": { "limit": 50, "cursor": null, "next_cursor": null, "has_more": false } }
curl "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates?limit=25&after=$NEXT_CURSOR" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

Errors shared by every template endpoint

  • 404 account_not_found — the account is not on this project.
  • 409 account_inactive — the account is switched off; templates are managed on live accounts only.
  • 409 account_reauthorization_required — the account's authorization has expired; mint a connect link and have the customer reconnect.
  • 409 business_account_unknown — the account was connected by hand and carries no WhatsApp Business Account id. Set it once with PUT /whatsapp/accounts/{accountId} and business_account_id (it is stored only after WhatsApp confirms the account's own token can read it), or reconnect the number through a connect link, which records it by itself.
  • 400 whatsapp_template_refused — WhatsApp refused the request; error.message carries its own explanation (a name already in use, a variable without an example value, a category that does not fit the text…) and error.details its whatsapp_code / whatsapp_subcode.
  • 404 template_not_found — no template with that id on this account. An id from another account answers this too, whatever the token could reach.
  • 403 whatsapp_permission_denied — the account's token cannot manage templates; reconnect through a connect link.
  • 429 whatsapp_rate_limited — WhatsApp is throttling template operations on this account (it caps creations per hour); retry after Retry-After. 429 rate_limit_exceeded is your own key's limit, as on every write.
  • 502 whatsapp_template_failed / whatsapp_unreachable — WhatsApp did not answer or answered with an outage; error.details.retryable is true. On a create, read the list before retrying: the template may exist.
POST/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates#

Create a template

Submits a message template to WhatsApp for review on the account's business account. WhatsApp reviews it asynchronously — usually within minutes, sometimes longer: the template comes back with status PENDING, and the outcome (APPROVED or REJECTED with a reason) reaches you as a whatsapp.template.status webhook event and on GET. Nothing is generated on your behalf: the text is yours, and WhatsApp judges it against its template policies.

Authentication

Bearer <admin_api_key> — subject to the key's rate limit (429 rate_limit_exceeded with Retry-After).

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "category": "\"MARKETING\" | \"UTILITY\" | \"AUTHENTICATION\"",
  "language": "string",
  "components": "array",
  "app_id": "string",
  "allow_category_change": "boolean",
  "parameter_format": "\"POSITIONAL\" | \"NAMED\"",
  "message_send_ttl_seconds": "integer"
}
Fields8Expand
name
stringrequired
lowercase letters, digits and underscores, max 512. Unique per language on the account; a deleted name cannot be reused for 30 days
category
"MARKETING" | "UTILITY" | "AUTHENTICATION"required
case-insensitive — WhatsApp prices conversations by it and rejects a text that does not fit the category
language
stringrequired
a WhatsApp language code such as "es", "es_MX" or "en_US"
components
arrayrequired
1-10 — the parts of the message, passed to WhatsApp as given. A BODY is required. Each has a type: HEADER (format TEXT / IMAGE / VIDEO / DOCUMENT / LOCATION), BODY (text, max 1024 chars, variables as {{1}} or {{name}}), FOOTER (text), BUTTONS (buttons[]: QUICK_REPLY, URL, PHONE_NUMBER, COPY_CODE…). Every variable needs an example value (example.body_text / example.header_text) or WhatsApp refuses the template. An IMAGE, VIDEO or DOCUMENT header needs its sample: give example.header_url (a public https URL of a JPEG, PNG, MP4 or PDF — fetched and uploaded for you in this same call) or example.header_handle (the handle of a sample uploaded beforehand with POST …/templates/media). Missing both is a 400 naming components.N.example.header_handle
app_id
stringoptional
only for an account you configured by hand with your own token, when a header carries example.header_url: the numeric id of the app that issued the token (as in POST …/templates/media)
allow_category_change
booleanoptional
let WhatsApp file the template under the category it judges correct instead of rejecting it
parameter_format
"POSITIONAL" | "NAMED"optional
how the variables are written; POSITIONAL unless said otherwise
message_send_ttl_seconds
integeroptional
-1 or 30…2592000 — how long WhatsApp keeps trying to deliver a message of this template; -1 is the category default

Response Schema

JSON type shapeExpand
{
  "…": "the template, same shape as a row of GET /templates, with status \"PENDING\" (or already \"APPROVED\" for some utility texts WhatsApp clears at once), HTTP 201"
}
Fields1Expand
…
the template, same shape as a row of GET /templates, with status "PENDING" (or already "APPROVED" for some utility texts WhatsApp clears at once), HTTP 201

Code Examples

The example values are what WhatsApp's reviewers see in place of the variables; the template is refused without them.

curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "order_update",
    "category": "UTILITY",
    "language": "es",
    "components": [
      { "type": "BODY",
        "text": "Hola {{1}}, tu pedido {{2}} sale mañana. ¿Necesitas algo más?",
        "example": { "body_text": [["Ana", "4521"]] } },
      { "type": "FOOTER", "text": "Acme" },
      { "type": "BUTTONS", "buttons": [ { "type": "QUICK_REPLY", "text": "Sí, gracias" } ] }
    ]
  }'
# → 201 { "id": "1011820805234855", "name": "order_update", "language": "es", "status": "PENDING", "category": "UTILITY", … }
# later, on your webhook: { "event": "whatsapp.template.status", "data": { "template": { "id": "1011820805234855", … }, "status": "APPROVED", … } }

Give the header its sample as a public URL: the file is fetched, uploaded to WhatsApp and the handle put in its place before the template is submitted — nothing to copy between calls. The same works on an edit (PUT).

curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "spring_sale",
    "category": "MARKETING",
    "language": "es",
    "components": [
      { "type": "HEADER", "format": "IMAGE", "example": { "header_url": "https://acme.example/img/spring-hero.jpg" } },
      { "type": "BODY", "text": "Hola {{1}}, llegó la primavera: 20% en todo hasta el domingo.", "example": { "body_text": [["Ana"]] } }
    ]
  }'
# → 201 { "id": "…", "status": "PENDING", "components": [ { "type": "HEADER", "format": "IMAGE", "example": { "header_handle": ["4::…"] } }, … ] }

The two-call form: a media header with a header_handle example — the handle POST …/templates/media answers with for a sample file (its header_component is exactly the first component below). Buttons with a URL may carry one variable at the end of the link.

curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "spring_sale",
    "category": "MARKETING",
    "language": "en_US",
    "allow_category_change": true,
    "components": [
      { "type": "HEADER", "format": "IMAGE", "example": { "header_handle": ["4::aW1hZ2UvanBlZw==:ARZ…"] } },
      { "type": "BODY", "text": "Spring is here, {{1}}. 20% off everything until Sunday.", "example": { "body_text": [["Ana"]] } },
      { "type": "BUTTONS", "buttons": [ { "type": "URL", "text": "Shop now", "url": "https://acme.example/sale/{{1}}", "example": ["ana-20"] } ] }
    ]
  }'

Details

What WhatsApp enforces

  • Review is asynchronous. Listen to whatsapp.template.status or poll GET /templates/{templateId}; do not send a template until it is APPROVED — a send of a pending or rejected template is refused with whatsapp_send_failed.
  • One name, several languages. Creating the same name in a second language is a second template with its own id and its own review; send it with the matching template.language.
  • Limits are the account's. WhatsApp caps how many templates a business account may hold and how many can be created per hour; the refusal comes back as whatsapp_template_refused or whatsapp_rate_limited.
  • Quality follows the template. Recipients who block or report the number lower its quality; a RED template can be PAUSED and then DISABLED by WhatsApp — both arrive as whatsapp.template.status events, and whatsapp.template.quality reports the rating changes themselves.
  • Nothing is billed by Ainvented. A template call is free at WhatsApp and unpriced here; every create, edit and delete is written to the project's audit log with the key that made it.
POST/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates/media#

Upload a header sample

The sample file a template with an IMAGE, VIDEO or DOCUMENT header is reviewed against. WhatsApp takes it through its own upload and hands back a handle; this endpoint does that upload with the account's authorization — which never leaves the server — and answers with the handle, plus the HEADER component ready to paste into POST /templates. If the sample sits at a public URL you can skip this call: put it in the header's example.header_url when creating or editing the template and the upload happens there. Hand the file over as multipart/form-data (a file part) or as a public https url this server fetches. WhatsApp accepts JPEG and PNG (up to 5 MB), MP4 (16 MB) and PDF (100 MB); this server buffers up to 25 MB by default. A handle is tied to the account's app and expires after a while at WhatsApp, so upload right before creating the template.

Authentication

Bearer <admin_api_key> — subject to the key's rate limit (429 rate_limit_exceeded with Retry-After).

Request Schema

JSON type shapeExpand
{
  "file": "multipart part",
  "url": "https url (JSON body, instead of file)",
  "file_name": "string",
  "mime_type": "string",
  "app_id": "string"
}
Fields5Expand
file
multipart part
the sample bytes, with its Content-Type (image/jpeg, image/png, video/mp4 or application/pdf)
url
https url (JSON body, instead of file)
a public address this server fetches the sample from; must not resolve to a private network
file_name
stringoptional
both forms — the name WhatsApp files the sample under; the part's or the URL's last segment unless given
mime_type
stringoptional
both forms — overrides the type the part or the URL declares
app_id
stringoptional
only for an account you configured by hand with your own token: the numeric id of the app that issued it. Accounts connected through a connect link upload on Ainvented's app and must not send it

Response Schema

JSON type shapeExpand
{
  "handle": "string",
  "account_id": "uuid",
  "format": "\"IMAGE\" | \"VIDEO\" | \"DOCUMENT\"",
  "mime_type": "string",
  "size": "integer",
  "file_name": "string",
  "header_component": "{ type: \"HEADER\", format, example: { header_handle: [handle] } }"
}
Fields7Expand
handle
string
WhatsApp's upload handle; put it in example.header_handle of the HEADER component
account_id
uuid
format
"IMAGE" | "VIDEO" | "DOCUMENT"
the header format this sample stands for
mime_type
string
size
integer
bytes uploaded
file_name
string
header_component
{ type: "HEADER", format, example: { header_handle: [handle] } }
the component, ready to paste (HTTP 201)

Code Examples

HANDLE=$(curl -s -X POST "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates/media" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -F "file=@hero.jpg;type=image/jpeg" | jq -r .handle)

curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "spring_sale",
    "category": "MARKETING",
    "language": "es",
    "components": [
      { "type": "HEADER", "format": "IMAGE", "example": { "header_handle": ["'$HANDLE'"] } },
      { "type": "BODY", "text": "Hola {{1}}, llegó la primavera: 20% en todo hasta el domingo.", "example": { "body_text": [["Ana"]] } }
    ]
  }'
curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates/media" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://acme.example/brochures/spring-2026.pdf" }'
# → 201 { "handle": "4::YXBwbGljYXRpb24vcGRm:ARZ…", "format": "DOCUMENT", "mime_type": "application/pdf", "size": 184213,
#          "file_name": "spring-2026.pdf", "header_component": { "type": "HEADER", "format": "DOCUMENT", "example": { "header_handle": ["4::…"] } } }

Details

Errors

  • 400 — no file part and no url; an empty file (media_empty); a url that is not public https, or that could not be fetched (sample_unreachable); app_id_required for an account you configured by hand; a malformed app_id.
  • 415 unsupported_media_type — not JPEG, PNG, MP4 or PDF.
  • 413 media_too_large — over WhatsApp's cap for the format, or over this server's buffer.
  • 404 account_not_found · 409 account_inactive / account_reauthorization_required / business_account_unknown — the same account rules as every template call.
  • 403 whatsapp_permission_denied — the account's token cannot upload on that app (a hand-made account: check app_id).
  • 502 whatsapp_template_failed / whatsapp_unreachable — WhatsApp did not take the file; retry.
  • 503 whatsapp_upload_unavailable — uploads are not configured on this server.
GET/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates/{templateId}#

Read a template

One template of the account, by the id WhatsApp gave it — the same id the whatsapp.template.* events carry, so a webhook delivery can be followed up with this call. The id is looked up under this account's business account first: another account's template answers 404 template_not_found.

Authentication

Bearer <admin_api_key>

Response Schema

JSON type shapeExpand
{
  "…": "the template, same shape as a row of GET /templates"
}
Fields1Expand
…
the template, same shape as a row of GET /templates

Code Examples

curl "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates/$TEMPLATE_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → { "id": "…", "name": "order_update", "language": "es", "status": "REJECTED", "rejected_reason": "INVALID_FORMAT", … }
PUT/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates/{templateId}#

Edit a template

Changes the components, the category, the parameter format or the delivery TTL of one template. WhatsApp only edits a template that is APPROVED, REJECTED or PAUSED — never one PENDING or DISABLED — allows an approved template one edit a day and ten a month, and sends any change of the text back to review: the answer is the template as WhatsApp now holds it, usually PENDING again. The id is looked up under this account's business account first.

Authentication

Bearer <admin_api_key> — subject to the key's rate limit.

Request Schema

JSON type shapeExpand
{
  "components": "array",
  "category": "\"MARKETING\" | \"UTILITY\" | \"AUTHENTICATION\"",
  "parameter_format": "\"POSITIONAL\" | \"NAMED\"",
  "message_send_ttl_seconds": "integer"
}
Fields4Expand
components
arrayoptional
1-10, a BODY required — replaces every component; same rules as on creation. A media HEADER takes example.header_url (uploaded for you) or example.header_handle
category
"MARKETING" | "UTILITY" | "AUTHENTICATION"optional
parameter_format
"POSITIONAL" | "NAMED"optional
message_send_ttl_seconds
integeroptional
-1 or 30…2592000

Response Schema

JSON type shapeExpand
{
  "…": "the template after the change, same shape as a row of GET /templates"
}
Fields1Expand
…
the template after the change, same shape as a row of GET /templates

Code Examples

curl -X PUT "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates/$TEMPLATE_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "components": [
      { "type": "BODY", "text": "Hola {{1}}, tu pedido {{2}} sale mañana.", "example": { "body_text": [["Ana", "4521"]] } }
    ]
  }'
# → 200 { "id": "…", "status": "PENDING", … }   ← reviewed again; the whatsapp.template.status event tells the outcome
DELETE/api/v1/projects/{projectId}/whatsapp/accounts/{accountId}/templates/{templateId}#

Delete a template

Deletes one template — that name in that language — from the account's business account. WhatsApp moves it to PENDING_DELETION (messages already sent with it still deliver for a while), and the name cannot be reused for 30 days. To delete a name in every language at once, call DELETE /whatsapp/accounts/{accountId}/templates?name={name} instead. The id is looked up under this account's business account first.

Authentication

Bearer <admin_api_key> — subject to the key's rate limit.

Response Schema

JSON type shapeExpand
{
  "deleted": "true",
  "account_id": "uuid",
  "id": "string | null",
  "name": "string",
  "language": "string | null"
}
Fields5Expand
deleted
true
account_id
uuid
id
string | null
the id deleted; null when deleting by name
name
string
language
string | null
null when deleting by name (every language went)

Code Examples

curl -X DELETE "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates/$TEMPLATE_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → { "deleted": true, "account_id": "…", "id": "1011820805234855", "name": "order_update", "language": "es" }
curl -X DELETE "$BASE/api/v1/projects/$PID/whatsapp/accounts/$ACCOUNT_ID/templates?name=order_update" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → { "deleted": true, "account_id": "…", "id": null, "name": "order_update", "language": null }
POST/api/v1/projects/{projectId}/whatsapp/webhooks#

Register a webhook

Where inbound messages of the project's API-mode accounts are delivered, and optionally the delivery statuses of the messages you send. A hook may listen to every account of the project or to one account. It is a project webhook — same signature, retries and auto-disable rules as the budget hooks — and its secret is returned once, here.

Authentication

Bearer <admin_api_key>

Request Schema

JSON type shapeExpand
{
  "url": "https url",
  "account_id": "uuid | null",
  "events": "[\"whatsapp.message.received\", \"whatsapp.message.status\", \"whatsapp.template.status\", \"whatsapp.template.category\", \"whatsapp.template.quality\"]"
}
Fields3Expand
url
https urlrequired
public host; private and loopback addresses are refused
account_id
uuid | nulloptional
deliver only this account's events; omit or null for every account of the project
events
["whatsapp.message.received", "whatsapp.message.status", "whatsapp.template.status", "whatsapp.template.category", "whatsapp.template.quality"]optional
default ["whatsapp.message.received"]. The template events report WhatsApp's review outcome, a category change and a quality change of the account's message templates

Response Schema

JSON type shapeExpand
{
  "id": "uuid",
  "url": "string",
  "account_id": "uuid | null",
  "events": "string[]",
  "is_active": "boolean",
  "secret": "hex string",
  "created_at": "ISO timestamp",
  "updated_at": "ISO timestamp",
  "last_delivery_at": "ISO timestamp | null",
  "failure_count": "integer"
}
Fields10Expand
id
uuid
url
string
account_id
uuid | null
events
string[]
is_active
boolean
secret
hex string
shown ONCE; sign-check every delivery with it
created_at
ISO timestamp
updated_at
ISO timestamp
last_delivery_at
ISO timestamp | null
failure_count
integer
consecutive failed deliveries; the hook is disabled at 20

Code Examples

curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/webhooks" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://acme.example/whatsapp/inbound",
    "account_id": "'$ACCOUNT_ID'",
    "events": ["whatsapp.message.received", "whatsapp.message.status"]
  }'
# → 201 { "id": "…", "secret": "0f3a…", … }   ← store the secret now
GET/api/v1/projects/{projectId}/whatsapp/webhooks#

Manage webhooks

Lists the project's WhatsApp webhooks (budget hooks of the same project are not shown here, nor are these shown as WhatsApp hooks elsewhere). Each one is also reachable at /whatsapp/webhooks/{webhookId}: GET reads it, PUT changes url, events, account_id, is_active or rotates the secret, DELETE deactivates it, and POST /whatsapp/webhooks/{webhookId}/test sends a signed sample event with data.test = true so you can check your endpoint before real traffic.

Authentication

Bearer <admin_api_key>

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "include_disabled": "true"
}
Fields2Expand
account_id
uuidoptional
query — the hooks that would fire for this account: its own and the project-wide ones
include_disabled
trueoptional
query

Response Schema

JSON type shapeExpand
{
  "data[]": "the webhook objects, without secrets"
}
Fields1Expand
data[]
the webhook objects, without secrets

Code Examples

curl -X PUT "$BASE/api/v1/projects/$PID/whatsapp/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "rotate_secret": true }'
# → 200 { …, "secret": "new hex" }
curl -X POST "$BASE/api/v1/projects/$PID/whatsapp/webhooks/$WEBHOOK_ID/test" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → 202 { "delivered": true, "attempts": 1, "event_id": "…" }
curl -X DELETE "$BASE/api/v1/projects/$PID/whatsapp/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → 204
GET/api/v1/projects/{projectId}/whatsapp/traffic#

Traffic of a project

Messages per day on one project — received, sent and failed — zero-filled over the window, plus how many people wrote and how many numbers are active. One grouped query whatever the volume; the Partner Console draws its WhatsApp chart from it.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "from": "string",
  "to": "string",
  "group_by": "string",
  "account_id": "string"
}
Fields4Expand
from
stringoptional
ISO datetime or YYYY-MM-DD. Defaults to 30 days before to.
to
stringoptional
ISO datetime or YYYY-MM-DD (a bare date is inclusive of its whole day). Defaults to now. The window may not exceed 90 days.
group_by
stringoptional
"day" (default) or "account". "account" adds a per-number breakdown.
account_id
stringoptional
Narrow the report to one number.

Response Schema

JSON type shapeExpand
{
  "project_id": "string",
  "window": {
    "from": "string",
    "to": "string"
  },
  "group_by": "string",
  "totals": {
    "inbound": "integer",
    "outbound": "integer",
    "total": "integer",
    "failed": "integer",
    "active_conversations": "integer",
    "accounts": "integer"
  },
  "series": [
    {
      "bucket": "string",
      "inbound": "integer",
      "outbound": "integer",
      "total": "integer",
      "failed": "integer"
    }
  ],
  "by_account": [
    {
      "account_id": "string",
      "project_id": "string",
      "name": "string | null",
      "display_phone_number": "string | null",
      "inbound": "integer",
      "outbound": "integer",
      "total": "integer",
      "failed": "integer"
    }
  ]
}
Fields27Expand
project_id
string
The project.
window
object
object — fields below
from
string
ISO
to
string
ISO
group_by
string
What was asked for.
totals
object
object — fields below
inbound
integer
Messages received in the window.
outbound
integer
Messages sent (through the API or by the assistant).
total
integer
failed
integer
Messages whose status is failed.
active_conversations
integer
People who wrote in the window.
accounts
integer
Active numbers on the project.
series
array
array — fields below
bucket
string
YYYY-MM-DD (UTC)
inbound
integer
outbound
integer
total
integer
failed
integer
by_account
array
array — fields below
account_id
string
project_id
string
name
string | null
display_phone_number
string | null
inbound
integer
outbound
integer
total
integer
failed
integer

Code Examples

curl "$BASE/api/v1/projects/$PID/whatsapp/traffic?from=2026-08-01&to=2026-08-31&group_by=account" \
  -H "Authorization: Bearer $API_KEY"
{
  "project_id": "…",
  "window": { "from": "2026-08-01T00:00:00.000Z", "to": "2026-09-01T00:00:00.000Z" },
  "group_by": "account",
  "totals": { "inbound": 412, "outbound": 388, "total": 800, "failed": 3, "active_conversations": 96, "accounts": 2 },
  "series": [
    { "bucket": "2026-08-01", "inbound": 14, "outbound": 12, "total": 26, "failed": 0 },
    { "bucket": "2026-08-02", "inbound": 0, "outbound": 0, "total": 0, "failed": 0 }
  ],
  "by_account": [
    { "account_id": "…", "project_id": "…", "name": "Acme Support", "display_phone_number": "+1 555 111 1111", "inbound": 400, "outbound": 380, "total": 780, "failed": 3 }
  ]
}
GET/api/v1/whatsapp/accounts#

Every number, all projects

Every WhatsApp number connected to any of your projects, in one paged list with its project, its mode and how many people wrote to it. The account-wide counterpart of the per-project list — one call for a thousand projects, never one per project.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "mode": "string",
  "include_inactive": "boolean",
  "project_ids": "string",
  "limit": "integer",
  "offset": "integer"
}
Fields5Expand
mode
stringoptional
"api" or "assistant".
include_inactive
booleanoptional
Include deactivated numbers.
project_ids
stringoptional
Comma-separated project UUIDs (at most 1000) to narrow the list. Ids you do not own simply do not match.
limit
integeroptional
1..200, default 50.
offset
integeroptional
default 0.

Response Schema

JSON type shapeExpand
{
  "data": [
    {
      "id": "string",
      "project_id": "string",
      "name": "string",
      "mode": "string",
      "display_phone_number": "string | null",
      "verified_name": "string | null",
      "is_active": "boolean",
      "needs_reconnect": "boolean",
      "conversation_count": "integer",
      "last_inbound_at": "string | null",
      "webhook_count": "integer",
      "project": {
        "id": "string",
        "name": "string | null"
      }
    }
  ],
  "page": {
    "limit": "integer",
    "offset": "integer",
    "has_more": "boolean"
  }
}
Fields19Expand
data
array
array — fields below
id
string
project_id
string
name
string
mode
string
"api" | "assistant"
display_phone_number
string | null
verified_name
string | null
is_active
boolean
needs_reconnect
boolean
conversation_count
integer
last_inbound_at
string | null
webhook_count
integer
Active whatsapp.* hooks that would fire for this number.
project
object
object — fields below
id
string
name
string | null
page
object
object — fields below
limit
integer
offset
integer
has_more
boolean

Code Examples

curl "$BASE/api/v1/whatsapp/accounts?mode=api&limit=100" \
  -H "Authorization: Bearer $API_KEY"
PUT/api/v1/whatsapp/accounts#

Bulk mode / active

Set who answers — and whether a number is active — on every WhatsApp number of your projects in one call, or on a selection by project and/or by number. One transaction; one whatsapp.account.update audit row (marked bulk) per number whose stored value actually changes; a re-apply writes nothing.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "mode": "string",
  "is_active": "boolean",
  "project_ids": "string[]",
  "account_ids": "string[]"
}
Fields4Expand
mode
stringoptional
"api" or "assistant". At least one of mode / is_active is required.
is_active
booleanoptional
project_ids
string[]optional
1..1000 project UUIDs. Absent = every non-deleted project of the account.
account_ids
string[]optional
1..1000 number ids, further narrowing the selection.

Response Schema

JSON type shapeExpand
{
  "matched": "integer",
  "updated": "integer",
  "mode": "string",
  "is_active": "boolean"
}
Fields4Expand
matched
integer
Numbers in scope.
updated
integer
Numbers whose stored value changed.
mode
stringoptional
Echoed when sent.
is_active
booleanoptional
Echoed when sent.

Code Examples

curl -X PUT "$BASE/api/v1/whatsapp/accounts" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{ "mode": "api", "project_ids": ["'"$PID"'"] }'
{ "matched": 3, "updated": 2, "mode": "api" }
GET/api/v1/whatsapp/traffic#

Traffic, all projects

The same report as the per-project traffic, across every project you own (or a project_ids selection), with an optional per-project breakdown. Every figure comes from a grouped query on the message index — never from message rows — so it costs the same for one project as for a thousand.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "from": "string",
  "to": "string",
  "group_by": "string",
  "project_ids": "string",
  "account_id": "string"
}
Fields5Expand
from
stringoptional
ISO datetime or YYYY-MM-DD. Defaults to 30 days before to.
to
stringoptional
ISO datetime or YYYY-MM-DD. Defaults to now. At most 90 days after from.
group_by
stringoptional
"day" (default), "project" or "account".
project_ids
stringoptional
Comma-separated project UUIDs (at most 1000).
account_id
stringoptional
Narrow the report to one number.

Response Schema

JSON type shapeExpand
{
  "project_id": "null",
  "project_count": "integer",
  "window": {
    "from": "string",
    "to": "string"
  },
  "group_by": "string",
  "totals": {
    "inbound": "integer",
    "outbound": "integer",
    "total": "integer",
    "failed": "integer",
    "active_conversations": "integer",
    "accounts": "integer"
  },
  "series": [
    {
      "bucket": "string",
      "inbound": "integer",
      "outbound": "integer",
      "total": "integer",
      "failed": "integer"
    }
  ],
  "by_project": [
    {
      "project_id": "string",
      "name": "string | null",
      "inbound": "integer",
      "outbound": "integer",
      "total": "integer",
      "failed": "integer"
    }
  ],
  "by_account": [
    {
      "account_id": "string",
      "project_id": "string",
      "name": "string | null",
      "display_phone_number": "string | null",
      "inbound": "integer",
      "outbound": "integer",
      "total": "integer",
      "failed": "integer"
    }
  ]
}
Fields35Expand
project_id
null
project_count
integer
Projects in scope.
window
object
object — fields below
from
string
ISO
to
string
ISO
group_by
string
totals
object
object — fields below
inbound
integer
outbound
integer
total
integer
failed
integer
active_conversations
integer
accounts
integer
series
array
array — fields below
bucket
string
YYYY-MM-DD (UTC)
inbound
integer
outbound
integer
total
integer
failed
integer
by_project
array
array — fields below
project_id
string
name
string | null
inbound
integer
outbound
integer
total
integer
failed
integer
by_account
array
array — fields below
account_id
string
project_id
string
name
string | null
display_phone_number
string | null
inbound
integer
outbound
integer
total
integer
failed
integer

Code Examples

curl "$BASE/api/v1/whatsapp/traffic?group_by=project" \
  -H "Authorization: Bearer $API_KEY"
POST/api/v1/whatsapp/webhooks#

Webhook on every project

Register one webhook URL on every project you own (or a project_ids selection) in a single call. One secret is minted for the whole batch and returned once, so an application that receives every customer's messages at one endpoint verifies every delivery with one key. A project that already has an active project-wide hook on that URL is left alone and reported as reused.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "url": "string",
  "events": "string[]",
  "project_ids": "string[]"
}
Fields3Expand
url
stringrequired
https URL; private, loopback and link-local addresses are refused.
events
string[]optional
whatsapp.message.received (default) and/or whatsapp.message.status.
project_ids
string[]optional
1..1000 project UUIDs. Absent = every non-deleted project of the account.

Response Schema

JSON type shapeExpand
{
  "secret": "string | null",
  "created": "integer",
  "reused": "integer",
  "webhooks": [
    {
      "id": "string",
      "project_id": "string",
      "url": "string",
      "events": "string[]",
      "is_active": "boolean",
      "reused": "boolean",
      "created_at": "string"
    }
  ]
}
Fields11Expand
secret
string | null
The one secret shared by every hook created — shown ONCE. null when nothing was created.
created
integer
reused
integer
webhooks
array
array — fields below
id
string
project_id
string
url
string
events
string[]
is_active
boolean
reused
boolean
created_at
string

Code Examples

curl -X POST "$BASE/api/v1/whatsapp/webhooks" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{ "url": "https://acme.example/whatsapp/inbound", "events": ["whatsapp.message.received", "whatsapp.message.status"] }'
{
  "secret": "9b1f…",
  "created": 41,
  "reused": 2,
  "webhooks": [
    { "id": "…", "project_id": "…", "url": "https://acme.example/whatsapp/inbound", "events": ["whatsapp.message.received", "whatsapp.message.status"], "is_active": true, "reused": false, "created_at": "2026-09-03T10:00:00.000Z" }
  ]
}
Guide

Webhook payload & signature

Every delivery is a JSON POST with the headers X-Ainvented-Event, X-Ainvented-Delivery (the event id) and X-Ainvented-Signature: sha256= followed by the hex HMAC-SHA256 of the raw body under your webhook's secret. Verify it before trusting a payload. Answer with any 2xx within 8 seconds; anything else is retried once, 2 seconds later, and the message is marked webhook.status = "failed" for you to read back. Deliveries are at-least-once and idempotent on the message id, so a duplicate event carries the same data.message.id.

Delivery
POST https://acme.example/whatsapp/inbound
X-Ainvented-Event: whatsapp.message.received
X-Ainvented-Delivery: 3f6c1a2e-…
X-Ainvented-Signature: sha256=9b1f…

{
  "id": "3f6c1a2e-…",
  "event": "whatsapp.message.received",
  "occurred_at": "2026-09-03T10:15:02.114Z",
  "project_id": "…",
  "data": {
    "message": {
      "id": "…", "account_id": "…", "conversation_id": "…",
      "direction": "inbound", "wa_message_id": "wamid.…",
      "from": "34600111222", "to": "15551111111",
      "type": "image", "text": "is this the blue one?",
      "media": { "id": "1042…", "mime_type": "image/jpeg", "sha256": "…" },
      "status": "received", "error": null,
      "sent_at": "2026-09-03T10:15:00.000Z", "delivered_at": null, "read_at": null,
      "webhook": { "status": "pending", "delivered_at": null },
      "api_key_id": null, "created_at": "2026-09-03T10:15:02.010Z",
      "referral": null,
      "payload": { "from": "34600111222", "id": "wamid.…", "timestamp": "1788776100", "type": "image",
                   "image": { "id": "1042…", "mime_type": "image/jpeg", "sha256": "…", "caption": "is this the blue one?" } }
    },
    "account": { "id": "…", "name": "Acme Support", "display_phone_number": "+1 555 111 1111", "phone_number_id": "…" },
    "conversation": { "id": "…", "phone": "34600111222", "profile_name": "Ana", "inbound_count": 3, "outbound_count": 2, "…": "…" }
  }
}

data.message.payload is the message exactly as WhatsApp delivered it (since 2026-09-16, on every event — the same object include_payload=true returns). The first-class fields summarise; the payload carries the whole content of the types that do not fit a text: the phones, emails and organisation of a contacts card, the coordinates of a location, the id of the button or row pressed in an interactive reply (payload.interactive.button_reply.id / list_reply.id), a button tapped on a template, a reaction with the id of the message it reacts to, an order with its items — and any field WhatsApp adds later, without waiting for us to model it. data.message.referral is the ad or post the customer came from, or null.

A whatsapp.message.status event carries data.status (sent, delivered, read or failed) and the outbound data.message it refers to, already updated.

The template events carry data.template (id, name, language) and data.account (with its business_account_id). whatsapp.template.status adds data.status (APPROVED, REJECTED, PAUSED, DISABLED, PENDING_DELETION…), data.reason and, on a pause or a disable, data.info and data.disabled_at; whatsapp.template.category adds previous_category, new_category and correct_category; whatsapp.template.quality adds previous_quality_score and new_quality_score. Deliveries are idempotent on the template, the new state and the moment WhatsApp reported it. Follow any of them up with GET /whatsapp/accounts/{accountId}/templates/{templateId}.

Template review outcome
{
  "id": "8a1d…", "event": "whatsapp.template.status", "occurred_at": "2026-09-10T18:43:36.000Z", "project_id": "…",
  "data": {
    "template": { "id": "1011820805234855", "name": "order_update", "language": "es" },
    "status": "APPROVED", "reason": null, "disabled_at": null, "info": null,
    "account": { "id": "…", "name": "Acme Support", "display_phone_number": "+1 555 111 1111", "phone_number_id": "…", "business_account_id": "…" }
  }
}
Node — verify a delivery
# Node — verify a delivery
const crypto = require('crypto');
const expected = 'sha256=' + crypto.createHmac('sha256', WEBHOOK_SECRET).update(rawBody).digest('hex');
const ok = expected.length === signature.length &&
  crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature));
Guide

What your customer goes through

The page you send them is hosted by Ainvented and needs no account. They sign in with Meta, choose or create a WhatsApp Business account, and verify a phone number. Meta asks them for a payment method: as a technology provider there is no credit line to share, so WhatsApp bills each customer directly for their own message usage. If the link carries their number, the page shows it and goes straight to Meta; otherwise it asks them for the number first (recommended, not required).

Limits worth designing around

  • Give us the number. Meta tells us an account was shared, not by whom. With phone_number on the link, the share is matched to it exactly — the connection completes even if your customer closes our page before it finishes, however many customers are connecting at the same time. Without it, only the page they keep open can finish the link, and they may be asked for the last digits of their number.
  • The number must be free. A phone number already registered on the WhatsApp Business API cannot be onboarded, and your customer must be able to receive Meta's verification code on it.
  • One number, one project. A number already active on a different project is refused with phone_number_in_use.
  • Reconnecting is the same call. If the same number comes back to the same project, the existing connector is refreshed in place rather than duplicated.
  • The access token does not expire, so your customers are never asked to reconnect on a schedule.
  • 24-hour window. WhatsApp only allows free-form replies within 24 hours of the end user's message. An assistant answers immediately so this rarely bites it; in API mode, a reply that comes later than that is refused with whatsapp_send_failed (code 131047) and only a template reopens the conversation.
  • Templates are managed here too. Create them with POST /whatsapp/accounts/{accountId}/templates, learn the review outcome from the whatsapp.template.status event, then send them by name with type: "template". An account connected by hand needs its business_account_id set once (PUT /whatsapp/accounts/{accountId}) before its templates can be managed.
Reference · 27 endpoints

Messenger

Attach a customer's Facebook Page to one of your projects. You call one endpoint, get back a URL and hand it to your customer — they sign in with Facebook, in Meta’s own window, and choose the Page to share. Neither you nor they ever see an access token; Ainvented obtains it from Meta server-side and stores it encrypted.

Once connected, the account appears on the project with a mode: either the project's assistant answers its messages (and, if you choose, its comments) by itself, or every message and comment is handed to your application through a webhook and you answer through the API, with nothing generated in between. Either way every message is stored, a person can step in from the console or through this API, and the traffic is readable per project or across all of them. All of these endpoints are reserved for reseller accounts and take an Admin API key.

In this section
  1. GuideAssistant vs API mode
  2. GuideThe messaging windows
  3. GuideComments
  4. POSTCreate a connect link/api/v1/projects/{projectId}/messenger/connect
  5. GETCheck connect links/api/v1/projects/{projectId}/messenger/connect
  6. GETList accounts/api/v1/projects/{projectId}/messenger/accounts
  7. GETRead an account/api/v1/projects/{projectId}/messenger/accounts/{accountId}
  8. PUTUpdate an account/api/v1/projects/{projectId}/messenger/accounts/{accountId}
  9. DELETEDisconnect an account/api/v1/projects/{projectId}/messenger/accounts/{accountId}
  10. GETWho wrote in/api/v1/projects/{projectId}/messenger/conversations
  11. GETRead a conversation/api/v1/projects/{projectId}/messenger/conversations/{conversationId}
  12. PUTPause or resume the assistant/api/v1/projects/{projectId}/messenger/conversations/{conversationId}
  13. GETRead messages/api/v1/projects/{projectId}/messenger/messages
  14. POSTSend a message/api/v1/projects/{projectId}/messenger/messages
  15. GETRead a message/api/v1/projects/{projectId}/messenger/messages/{messageId}
  16. GETDownload a file/api/v1/projects/{projectId}/messenger/media/{mediaId}
  17. GETRead comments/api/v1/projects/{projectId}/messenger/comments
  18. GETRead a comment/api/v1/projects/{projectId}/messenger/comments/{commentId}
  19. POSTReply to a comment/api/v1/projects/{projectId}/messenger/comments/{commentId}/replies
  20. POSTRegister a Messenger webhook/api/v1/projects/{projectId}/messenger/webhooks
  21. GETList webhooks/api/v1/projects/{projectId}/messenger/webhooks
  22. GETRead a webhook/api/v1/projects/{projectId}/messenger/webhooks/{webhookId}
  23. PUTUpdate a webhook/api/v1/projects/{projectId}/messenger/webhooks/{webhookId}
  24. DELETEDeactivate a webhook/api/v1/projects/{projectId}/messenger/webhooks/{webhookId}
  25. POSTTest a webhook/api/v1/projects/{projectId}/messenger/webhooks/{webhookId}/test
  26. GETTraffic of a project/api/v1/projects/{projectId}/messenger/traffic
  27. GETEvery account, all projects/api/v1/messenger/accounts
  28. PUTBulk mode / active / comments/api/v1/messenger/accounts
  29. GETTraffic, all projects/api/v1/messenger/traffic
  30. POSTWebhook on every project/api/v1/messenger/webhooks
  31. GuideWebhook payload & signature
  32. GuideWhat your customer sees
Guide

Assistant mode vs API mode

mode: "assistant" (default)mode: "api"
Who answersThe project's assistant, right away, inside Meta's 24-hour window. Same as connecting from the AI Chat view.Your application. Nothing is generated: the message is stored, delivered to your webhooks, and you reply — or not — with POST /messenger/messages.
CommentsWhat the account chose in comment_reply_mode: nothing (the default), a public answer, a private message, or both.Each new comment reaches your webhooks as messenger.comment.received; you answer with POST /messenger/comments/{commentId}/replies.
What it costs youEach message or comment the assistant answers is a priced assistant turn on the project, like a chat completion.No tokens are spent on the project, for anything received or sent. Messenger itself charges nothing per message.
HistoryBoth modes keep every message, both ways, in GET /messenger/conversations and GET /messenger/messages — the assistant's answers too, so a person can read a conversation and step in.
SwitchingAny time, without reconnecting: PUT /messenger/accounts/{accountId} with the new mode.
Guide

The messaging windows

Messenger only lets a business answer people who wrote first, and only for a while. Every conversation says where it stands in window.state, and every send is checked against it before anything leaves.

  • Within 24 hours of the person's last message (standard): anyone may answer — the assistant, your application, a person.
  • From 24 hours to 7 days (human_agent): only a reply typed by a person, sent with human_agent: true. It travels with Meta's Human Agent tag. The assistant stays silent; any other send is refused with human_agent_required.
  • After 7 days (closed): nothing can be sent until the person writes again (outside_messaging_window).
  • What opens a window: a message or a tapped button from the person. A reaction does not.
  • A person takes over. When a person replies — from the console, through this API with human_agent, or in Meta's own inbox — the assistant pauses in that conversation for 24 hours. PUT /messenger/conversations/{conversationId} pauses or resumes it at will.
  • The assistant says it is one. Its first reply of a conversation, and its first after a day without one, begins with the account's automation_notice, as Meta asks. Change it or switch it off with PUT /messenger/accounts/{accountId}.
human_agent is for people

Meta reviews how the Human Agent tag is used. Send human_agent: true only on words a person typed; marking automated messages with it can get the account's messaging restricted.

Guide

Comments: public, private or both

Every new comment on the posts of a connected Facebook Page is stored, in both modes, and readable in GET /messenger/comments. The account's own comments — its answers included — are never stored or answered.

  • Assistant mode does what comment_reply_mode says: off (the default) nothing; public an answer under the comment, as the account; private a message to the person; both the same answer both ways. One assistant turn per comment, priced like a message.
  • API mode delivers messenger.comment.received to your webhooks; answer with POST /messenger/comments/{commentId}/replies, publicly, privately or both.
  • One private reply per comment, within 7 days of it — Meta's rule, checked before anything is sent (can_private_reply). When the person answers it, the conversation goes on under the usual windows.
  • Facebook comments arrive through the Page's feed, with the author's name; a public answer is posted as the Page.
POST/api/v1/projects/{projectId}/messenger/connect#

Create a connect link

Mints a one-shot URL that walks your customer through Meta’s login and attaches their Facebook Page to this project. They sign in with Facebook, in Meta’s own window, and choose the Page to share. You get a URL and hand it over — no SDK, no Meta app of your own; neither you nor they ever see an access token. The link is single-use and expires after 7 days; a customer whose attempt failed (they cancelled in Meta’s window, or shared nothing) can try again on the same link until then. If the Facebook Page they pick is already live on another of your projects, the page offers to move it here — without naming that project to your customer; an account connected to someone else’s project is refused. The account it creates answers through the project’s assistant unless you ask for API mode.

Authentication

Bearer <admin_api_key> — must be an account-wide Admin key (no project binding), must own the project, and the account must be a reseller.

Request Schema

JSON type shapeExpand
{
  "connector_name": "string",
  "return_url": "url",
  "mode": "\"assistant\" | \"api\"",
  "comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\""
}
Fields4Expand
connector_name
stringoptional
1..100 chars — label for the account; omit it and the Facebook Page’s own name is used. On a reconnect, a name given here replaces the old one
return_url
urloptional
where the customer lands after connecting. Must be http or https; other schemes are a 400. Omit it and they stay on a success card.
mode
"assistant" | "api"optional
default "assistant" — who answers. "assistant": the project’s assistant replies by itself; "api": messages and comments go to your webhooks and you reply through this API. Applied to the account the link connects — also when it reconnects one this project already has, so name the mode you want kept.
comment_reply_mode
"off" | "public" | "private" | "both"optional
default "off" — what the assistant does with a new comment on the account’s posts: a public answer under it, a private message to the person, or both — a short public answer plus the full one in private. Read only in assistant mode. Applied on a reconnect too, like mode.

Response Schema

JSON type shapeExpand
{
  "connect_url": "the URL to hand your customer",
  "connect_token": "the token embedded in that URL; correlate with the list endpoint on it",
  "project_id": "uuid",
  "channel": "\"messenger\"",
  "status": "\"pending\" on creation",
  "connector_name": "string | null",
  "return_url": "string | null",
  "mode": "\"assistant\" | \"api\"",
  "comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\"",
  "expires_at": "ISO timestamp"
}
Fields10Expand
connect_url
the URL to hand your customer
https://<app>/connect/messenger/<token>
connect_token
the token embedded in that URL; correlate with the list endpoint on it
project_id
uuid
channel
"messenger"
status
"pending" on creation
connector_name
string | null
echoed back
return_url
string | null
echoed back
mode
"assistant" | "api"
the mode the account will be created in
comment_reply_mode
"off" | "public" | "private" | "both"
expires_at
ISO timestamp
after this the link is dead; mint another

Code Examples

Send the returned connect_url however you like: an email, a button in your own dashboard, a QR code. Your customer needs no Ainvented account.

curl -X POST "$BASE/api/v1/projects/$PID/messenger/connect" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "connector_name": "Acme Support",
    "mode": "api",
    "comment_reply_mode": "off",
    "return_url": "https://acme.example/settings/messenger?done=1"
  }'
# → 201 { "connect_url": "https://ainvented.com/connect/messenger/DlhaNJ_Jyaf...",
#         "connect_token": "DlhaNJ_Jyaf...", "status": "pending", "mode": "api",
#         "expires_at": "2026-11-17T20:17:38.262Z" }

Details

Errors

  • 403 admin_key_required — the key is bound to a project. Everything under /v1/projects/** is account management and needs an Admin key.
  • 403 messenger_not_enabled — the account is not approved for the Messenger endpoints. Every route under /messenger/ answers this for a non-reseller account.
  • 403 project_disabled — the project was deleted (reads stay allowed, writes do not).
  • 400 — a bad project id, a return_url that is not http(s), a mode or comment_reply_mode outside the listed values.
  • 503 messenger_not_configured — Messenger onboarding is not switched on for this deployment. Never a client bug; retry later.
GET/api/v1/projects/{projectId}/messenger/connect#

Check connect links

Lists the connect links issued for this project, newest first, so you can tell whether a customer finished. Poll it after handing a link over, or read it when your customer comes back to your app.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "status": "\"pending\" | \"selecting\" | \"completed\" | \"failed\" | \"expired\"",
  "limit": "integer",
  "offset": "integer"
}
Fields3Expand
status
"pending" | "selecting" | "completed" | "failed" | "expired"optional
query — filter. "selecting": the customer signed in and is choosing which account to connect. "failed": the last attempt failed (`error_code` says why); the link works until it expires
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].connect_token": "the token from the POST response",
  "data[].status": "\"pending\" | \"selecting\" | \"completed\" | \"failed\" | \"expired\"",
  "data[].connector_id": "uuid | null",
  "data[].connector_name": "string | null",
  "data[].mode": "\"assistant\" | \"api\"",
  "data[].comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\"",
  "data[].via": "\"connect_link\" | \"ai_chat\"",
  "data[].error_code": "string | null",
  "data[].error_message": "string | null",
  "data[].created_at": "ISO timestamp",
  "data[].expires_at": "ISO timestamp",
  "data[].completed_at": "ISO timestamp | null",
  "page": "{ limit, offset, has_more }"
}
Fields13Expand
data[].connect_token
the token from the POST response
correlate on this
data[].status
"pending" | "selecting" | "completed" | "failed" | "expired"
data[].connector_id
uuid | null
the account now live on the project, once status is "completed"
data[].connector_name
string | null
data[].mode
"assistant" | "api"
data[].comment_reply_mode
"off" | "public" | "private" | "both"
data[].via
"connect_link" | "ai_chat"
data[].error_code
string | null
cancelled | account_in_use | account_in_use_elsewhere | meta_login_failed | meta_accounts_unreadable | no_account_shared | subscription_failed | project_unavailable | server_error
data[].error_message
string | null
why the last attempt failed, in a sentence; the link still works, the customer can retry
data[].created_at
ISO timestamp
data[].expires_at
ISO timestamp
data[].completed_at
ISO timestamp | null
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/connect?status=completed" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

The listing never returns connect_url again

A link is a bearer capability — whoever holds it can attach an account to that project — so it is issued once and never re-exposed. To get another, POST again.

GET/api/v1/projects/{projectId}/messenger/accounts#

List connected accounts

The Facebook Pages attached to this project, with their mode, what the assistant does with comments, how many people wrote and how many of your webhooks fire for each. Inactive accounts are hidden unless asked for.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account. Same for every endpoint below.

Request Schema

JSON type shapeExpand
{
  "mode": "\"api\" | \"assistant\"",
  "include_inactive": "true"
}
Fields2Expand
mode
"api" | "assistant"optional
query — only accounts in that mode
include_inactive
trueoptional
query — also list switched-off and disconnected accounts

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].project_id": "uuid",
  "data[].channel": "\"messenger\"",
  "data[].name": "string",
  "data[].mode": "\"assistant\" | \"api\"",
  "data[].external_id": "string",
  "data[].display_name": "string | null",
  "data[].username": "null",
  "data[].comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\"",
  "data[].automation_notice": "string",
  "data[].business_id": "string | null",
  "data[].onboarded_via": "\"connect_link\" | \"ai_chat\" | null",
  "data[].is_active": "boolean",
  "data[].token_expires_at": "ISO timestamp | null",
  "data[].needs_reconnect": "boolean",
  "data[].connected_at": "ISO timestamp",
  "data[].updated_at": "ISO timestamp",
  "data[].conversation_count": "integer",
  "data[].last_inbound_at": "ISO timestamp | null",
  "data[].comment_count": "integer",
  "data[].webhook_count": "integer"
}
Fields21Expand
data[].id
uuid
the account_id used by every other endpoint
data[].project_id
uuid
data[].channel
"messenger"
data[].name
string
your label for the account
data[].mode
"assistant" | "api"
who answers its messages
data[].external_id
string
the Facebook Page’s own id on Facebook
data[].display_name
string | null
the Facebook Page’s name
data[].username
null
Pages have no username here
data[].comment_reply_mode
"off" | "public" | "private" | "both"
what the assistant does with a new comment (assistant mode only)
data[].automation_notice
string
the line put before the assistant’s first reply of a conversation (and before its private reply to a comment); by default "🤖 Asistente automático · Automated assistant"; "" when switched off
data[].business_id
string | null
the customer’s business portfolio id
data[].onboarded_via
"connect_link" | "ai_chat" | null
data[].is_active
boolean
data[].token_expires_at
ISO timestamp | null
null means the authorization does not expire on a schedule
data[].needs_reconnect
boolean
true once the authorization stopped working (or the account was disconnected); mint a new connect link
data[].connected_at
ISO timestamp
data[].updated_at
ISO timestamp
data[].conversation_count
integer
people who have written to this account
data[].last_inbound_at
ISO timestamp | null
data[].comment_count
integer
comments received on the account’s posts
data[].webhook_count
integer
your active messenger.* webhooks that fire for this account

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/accounts?mode=api" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/messenger/accounts/{accountId}#

Read an account

One connected account, same fields as the listing. An account of another project answers 404 account_not_found — an account id never resolves across projects.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the same object as one row of the listing"
}
Fields1Expand
…
the same object as one row of the listing

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/accounts/$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"
PUT/api/v1/projects/{projectId}/messenger/accounts/{accountId}#

Update an account

Rename an account, switch who answers it, choose what the assistant does with comments, change or switch off the automated-assistant notice, or switch the account off and on. Switching to API mode is how an account connected from the AI Chat view stops answering by itself and starts reaching your webhooks — the customer does not reconnect. Every change is written to the project’s audit log.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "mode": "\"api\" | \"assistant\"",
  "is_active": "boolean",
  "comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\"",
  "automation_notice": "string | null"
}
Fields5Expand
name
stringoptional
1..100 chars
mode
"api" | "assistant"optional
is_active
booleanoptional
false stops both directions: incoming messages are ignored and sends are refused with 409 account_inactive. true brings back an account that still holds its authorization
comment_reply_mode
"off" | "public" | "private" | "both"optional
automation_notice
string | nulloptional
up to 300 chars — the line put before the assistant’s first reply of a conversation (and again after a day without one). "" switches it off; null restores the default notice

Response Schema

JSON type shapeExpand
{
  "…": "the updated account, same shape as the listing"
}
Fields1Expand
…
the updated account, same shape as the listing

Code Examples

curl -X PUT "$BASE/api/v1/projects/$PID/messenger/accounts/$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "api" }'
curl -X PUT "$BASE/api/v1/projects/$PID/messenger/accounts/$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "assistant", "comment_reply_mode": "private" }'

Details

Errors

  • 400 — nothing to update, or a value outside the listed ones.
  • 409 account_reauthorization_required — is_active: true on an account that was disconnected: it holds no authorization any more. Mint a connect link.
  • 409 account_in_use — the same Facebook Page is active on another connection; switch that one off first.
  • 404 account_not_found — not an account of this project.
  • 403 project_disabled — the project was deleted.
DELETE/api/v1/projects/{projectId}/messenger/accounts/{accountId}#

Disconnect an account

Stops Messenger from delivering this account’s messages and comments to us, switches the account off and forgets its authorization. Its conversations, messages and comments stay readable. To bring it back, the customer connects it again through a new link — the same Facebook Page reconnected to the same project keeps its id and its history.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the account, now with is_active false and needs_reconnect true",
  "unsubscribed": "boolean"
}
Fields2Expand
…
the account, now with is_active false and needs_reconnect true
unsubscribed
boolean
whether Messenger confirmed it stopped delivering (false when it could not be reached; nothing is processed for a disconnected account either way). Also false when the same Facebook Page is active on another connection: it keeps receiving there

Code Examples

curl -X DELETE "$BASE/api/v1/projects/$PID/messenger/accounts/$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → 200 { "id": "…", "is_active": false, "needs_reconnect": true, "unsubscribed": true, … }

Details

Errors

  • 410 account_already_disconnected — it was disconnected before — also the answer to a second DELETE sent at the same time.
  • 404 account_not_found — not an account of this project.
GET/api/v1/projects/{projectId}/messenger/conversations#

Who wrote in

One row per person who has written to one of the project’s accounts, most recent message first — in both modes, so a conversation the assistant is having is readable too. Each row says where it stands against the messaging windows and whether the assistant is paused there. This is also the list of people you may write to.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "participant_id": "string",
  "since": "ISO datetime",
  "assistant": "\"paused\" | \"active\"",
  "limit": "integer",
  "offset": "integer"
}
Fields6Expand
account_id
uuidoptional
query — one account only; 404 if it is not on this project
participant_id
stringoptional
query — one person: the person’s Page-scoped id (PSID)
since
ISO datetimeoptional
query — conversations with a message from the person at or after this moment
assistant
"paused" | "active"optional
query — conversations where a person took over, or not
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].account_id": "uuid",
  "data[].channel": "\"messenger\"",
  "data[].participant_id": "string",
  "data[].name": "string | null",
  "data[].username": "null",
  "data[].first_inbound_at": "ISO timestamp | null",
  "data[].last_inbound_at": "ISO timestamp | null",
  "data[].last_outbound_at": "ISO timestamp | null",
  "data[].inbound_count": "integer",
  "data[].outbound_count": "integer",
  "data[].last_message": "{ direction: \"inbound\" | \"outbound\", preview: string } | null",
  "data[].window": "{ state: \"standard\" | \"human_agent\" | \"closed\", standard_until: ISO | null, human_agent_until: ISO | null }",
  "data[].assistant": "{ state: \"active\" | \"paused\", paused_until: ISO | null }",
  "data[].created_at": "ISO timestamp",
  "data[].updated_at": "ISO timestamp",
  "page": "{ limit, offset, has_more }"
}
Fields17Expand
data[].id
uuid
usable as conversation_id when reading or sending
data[].account_id
uuid
data[].channel
"messenger"
data[].participant_id
string
the person’s Page-scoped id (PSID); use it as `to` when replying
data[].name
string | null
the person’s name, as Meta shares it
data[].username
null
data[].first_inbound_at
ISO timestamp | null
data[].last_inbound_at
ISO timestamp | null
every window runs from here
data[].last_outbound_at
ISO timestamp | null
data[].inbound_count
integer
data[].outbound_count
integer
messages that left (failed sends not counted)
data[].last_message
{ direction: "inbound" | "outbound", preview: string } | null
data[].window
{ state: "standard" | "human_agent" | "closed", standard_until: ISO | null, human_agent_until: ISO | null }
what may be sent right now
data[].assistant
{ state: "active" | "paused", paused_until: ISO | null }
paused while a person handles the conversation
data[].created_at
ISO timestamp
data[].updated_at
ISO timestamp
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/conversations?account_id=$ACCOUNT_ID&since=$(date -u +%Y-%m-%dT00:00:00Z)" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/messenger/conversations/{conversationId}#

Read a conversation

One conversation, same fields as a row of the listing — read it before a person replies to see which window is open.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the same object as one row of the listing"
}
Fields1Expand
…
the same object as one row of the listing

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/conversations/$CONVERSATION_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

Errors

  • 404 conversation_not_found — not a conversation of this project and channel.
PUT/api/v1/projects/{projectId}/messenger/conversations/{conversationId}#

Pause or resume the assistant in one conversation

A person handling a conversation does not want the assistant talking over them. "paused" keeps the assistant silent in this conversation only (for 24 hours, or paused_hours); "active" lets it answer again right away. It is paused for you when a person replies — from the console, through this API with human_agent, or in Meta’s own inbox. Meaningful for assistant-mode accounts.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "assistant": "\"paused\" | \"active\"",
  "paused_hours": "integer"
}
Fields2Expand
assistant
"paused" | "active"required
paused_hours
integeroptional
1..720 — how long a pause lasts; default 24

Response Schema

JSON type shapeExpand
{
  "…": "the conversation, with assistant.state and assistant.paused_until updated"
}
Fields1Expand
…
the conversation, with assistant.state and assistant.paused_until updated

Code Examples

curl -X PUT "$BASE/api/v1/projects/$PID/messenger/conversations/$CONVERSATION_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "assistant": "active" }'

Details

Errors

  • 400 — assistant missing or not one of the two values, paused_hours out of range.
  • 404 conversation_not_found — not a conversation of this project and channel.
GET/api/v1/projects/{projectId}/messenger/messages#

Read messages

Every message on the project’s Messenger accounts, in both directions and both modes, newest first: what people sent, what the assistant answered, what you and your team sent, and what failed to send. Every incoming message is stored BEFORE any webhook delivery is attempted, so this is your catch-up when your endpoint was down — filter on since and order=asc.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "conversation_id": "uuid",
  "participant_id": "string",
  "direction": "\"inbound\" | \"outbound\"",
  "type": "text | image | video | audio | file | sticker | share | story_mention | story_reply | reaction | postback | referral | unsupported | unknown | unsent | deleted",
  "status": "received | sent | delivered | read | failed",
  "author": "customer | assistant | api | person | page_inbox | workflow",
  "since": "ISO datetime",
  "until": "ISO datetime",
  "order": "\"desc\" (default) | \"asc\"",
  "include_payload": "true",
  "limit": "integer",
  "offset": "integer"
}
Fields13Expand
account_id
uuidoptional
query
conversation_id
uuidoptional
query
participant_id
stringoptional
query — messages from or to this person
direction
"inbound" | "outbound"optional
query
type
text | image | video | audio | file | sticker | share | story_mention | story_reply | reaction | postback | referral | unsupported | unknown | unsent | deletedoptional
query
status
received | sent | delivered | read | failedoptional
query
author
customer | assistant | api | person | page_inbox | workflowoptional
query
since
ISO datetimeoptional
query — on the moment the message happened on Messenger
until
ISO datetimeoptional
query
order
"desc" (default) | "asc"
include_payload
trueoptional
query — include each event exactly as Messenger delivered it (inbound) or the request as it was sent (outbound)
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].account_id": "uuid",
  "data[].conversation_id": "uuid",
  "data[].channel": "\"messenger\"",
  "data[].direction": "\"inbound\" | \"outbound\"",
  "data[].message_id": "string | null",
  "data[].author": "\"customer\" | \"assistant\" | \"api\" | \"person\" | \"page_inbox\" | \"workflow\"",
  "data[].from": "string",
  "data[].to": "string",
  "data[].type": "text | image | video | audio | file | sticker | share | story_mention | story_reply | reaction | postback | referral | unsupported | unknown | unsent | deleted",
  "data[].text": "string | null",
  "data[].attachments": "[{ id, type, url, mime_type, name }]",
  "data[].tag": "\"HUMAN_AGENT\" | null",
  "data[].reply_to": "string | null",
  "data[].status": "\"received\" for inbound; \"sent\" → \"delivered\" → \"read\", or \"failed\", for outbound",
  "data[].error": "{ code, message } | null",
  "data[].sent_at": "ISO timestamp",
  "data[].delivered_at": "ISO timestamp | null",
  "data[].read_at": "ISO timestamp | null",
  "data[].webhook": "{ status: \"none\" | \"pending\" | \"delivered\" | \"partial\" | \"failed\", delivered_at } for an inbound message of an API-mode account (\"partial\": some of your hooks accepted it, not all); null otherwise",
  "data[].api_key_id": "uuid | null",
  "data[].created_at": "ISO timestamp",
  "data[].payload": "object | null",
  "page": "{ limit, offset, has_more }"
}
Fields24Expand
data[].id
uuid
data[].account_id
uuid
data[].conversation_id
uuid
data[].channel
"messenger"
data[].direction
"inbound" | "outbound"
data[].message_id
string | null
Messenger’s own id of the message
data[].author
"customer" | "assistant" | "api" | "person" | "page_inbox" | "workflow"
who wrote it: the person, the project’s assistant, your application, a person from the console, a person in Meta’s own inbox, or a workflow
data[].from
string
the sender’s id (the person’s, or the account’s external_id)
data[].to
string
the recipient’s id
data[].type
text | image | video | audio | file | sticker | share | story_mention | story_reply | reaction | postback | referral | unsupported | unknown | unsent | deleted
"unsent": the person took the message back on Messenger; "deleted": a person of the business removed it from Ainvented in the inbox (it stays on Messenger). Either way the message keeps its ids and times and no longer has its content
data[].text
string | null
the text; a pressed button’s title (postback); the emoji of a reaction; null once the message is "unsent" or "deleted"
data[].attachments
[{ id, type, url, mime_type, name }]
the files; id is what GET /media/{mediaId} takes, url is Meta’s own (it expires); empty once the message is "unsent" or "deleted"
data[].tag
"HUMAN_AGENT" | null
set on a reply a person sent after the 24-hour window
data[].reply_to
string | null
the message_id this one answers
data[].status
"received" for inbound; "sent" → "delivered" → "read", or "failed", for outbound
data[].error
{ code, message } | null
why an outbound message failed (`code` in the platform’s words, e.g. outside_messaging_window, meta_outcome_unknown; Meta’s own number is `meta_code` in the payload). On an incoming message of an assistant account: why the assistant did not answer it — assistant_usage_limit (the project reached its spending or token limit), assistant_failed (it could not answer, twice), assistant_outcome_unknown (its answer may not have reached the person and was not sent again)
data[].sent_at
ISO timestamp
when it happened on Messenger
data[].delivered_at
ISO timestamp | null
data[].read_at
ISO timestamp | null
data[].webhook
{ status: "none" | "pending" | "delivered" | "partial" | "failed", delivered_at } for an inbound message of an API-mode account ("partial": some of your hooks accepted it, not all); null otherwise
data[].api_key_id
uuid | null
the key that sent an outbound message
data[].created_at
ISO timestamp
data[].payload
object | null
only with include_payload=true (and on one message, and in every webhook event): the event exactly as Messenger delivered it, or the request as it was sent; null once the message is "unsent" or "deleted"
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/messages?direction=inbound&since=2026-11-10T08:00:00Z&order=asc&limit=200" \
  -H "Authorization: Bearer $ADMIN_KEY"
POST/api/v1/projects/{projectId}/messenger/messages#

Send a message

Sends a message from one of the project’s accounts to a person who has written to it — Messenger only lets a business answer people who wrote first. Within 24 hours of the person’s last message anything may be sent. From 24 hours to 7 days only a reply typed by a PERSON may go, and only marked with "human_agent": true (it travels with Meta’s HUMAN_AGENT tag — never use it for automated messages). After 7 days nothing can be sent until the person writes again. A long text is cut into several messages (2,000 characters each); a file goes as its own message after the text. Every attempt that reached Messenger is stored — a refused send is a message with status "failed" and its reason; a request refused before that (an invalid body, a closed window, an account that needs reconnecting) changes nothing and is not stored. Nothing is generated on your behalf. Retries: send an Idempotency-Key header (8-128 characters: letters, digits, _ . : -) and a retry of the same request — after a timeout or a lost answer — returns the first answer again, with the header Idempotent-Replayed: true, instead of sending a second message. Keys are kept 24 hours per project. The same key with a different body is refused (422); a retry while the first is still running gets 409. A refusal that sent nothing frees the key, so the corrected request can reuse it. When Messenger does not confirm a send in time, the answer is 504 meta_outcome_unknown: the message may have been delivered — do not resend it blindly (the conversation shows it as sent once Messenger’s echo arrives).

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account. Also subject to the key’s rate limit (429 rate_limit_exceeded with Retry-After).

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "to": "string",
  "conversation_id": "uuid",
  "Idempotency-Key": "header",
  "type": "\"text\" | \"image\" | \"video\" | \"audio\" | \"file\"",
  "text": "string (max 20,000)",
  "media_url": "https url",
  "reply_to": "not supported on Messenger",
  "human_agent": "boolean"
}
Fields9Expand
account_id
uuidrequired
the account to send from; must be active
to
string
the person’s Page-scoped id (PSID). Either to or conversation_id is required
conversation_id
uuid
the conversation to answer, instead of to
Idempotency-Key
headeroptional
recommended — 8-128 characters: letters, digits, _ . : -. A retry with the same key and body returns the first answer (Idempotent-Replayed: true) and sends nothing again
type
"text" | "image" | "video" | "audio" | "file"optional
"text" when there is no media_url; with a media_url and no type, the kind comes from the URL’s extension (.jpg .png .gif .webp → image, .mp4 .mov → video, .mp3 .m4a .ogg → audio, anything else → file)
text
string (max 20,000)
the text; past 2,000 characters it is sent as several messages. Required for type "text"; sent before the file for the other types
media_url
https url
where Meta fetches the file from; required for the file types (its kind is read from the extension when type is left out)
reply_to
not supported on Messenger
sending it is a 400
human_agent
booleanoptional
true ONLY for a reply typed by a person: allows it up to 7 days after the person’s last message, and lets a person step into an account the assistant answers (the assistant then pauses in that conversation)

Response Schema

JSON type shapeExpand
{
  "…": "the first stored message, same shape as a row of GET /messages, status \"sent\", HTTP 201",
  "additional_messages": "array"
}
Fields2Expand
…
the first stored message, same shape as a row of GET /messages, status "sent", HTTP 201
additional_messages
array
the other messages, when the text was cut into several or a file followed it

Code Examples

The Idempotency-Key makes a retry harmless: send the same request again with the same key and you get the first answer back, never a second message.

curl -X POST "$BASE/api/v1/projects/$PID/messenger/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Idempotency-Key: order-4521-shipped" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "to": "6712345678901234",
    "text": "Your order 4521 ships tomorrow. Anything else we can help with?"
  }'
# → 201 { "id": "…", "direction": "outbound", "author": "api", "status": "sent", "message_id": "…", "additional_messages": [] }
# The same request again → the same 201, with "Idempotent-Replayed: true" — nothing is sent twice

Only for a reply your agent typed. It is sent with Meta’s HUMAN_AGENT tag and stored with tag "HUMAN_AGENT".

curl -X POST "$BASE/api/v1/projects/$PID/messenger/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "conversation_id": "'$CONVERSATION_ID'",
    "text": "Hi Ana, I checked with the warehouse: your parcel left this morning.",
    "human_agent": true
  }'
curl -X POST "$BASE/api/v1/projects/$PID/messenger/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "to": "6712345678901234",
    "type": "file",
    "media_url": "https://acme.example/invoices/4521.pdf",
    "text": "Here is your invoice."
  }'
{
  "error": {
    "message": "More than 24 hours have passed since this person's last Messenger message. Only a reply typed by a person can be sent now (up to 7 days): send it with \"human_agent\": true.",
    "type": "invalid_request_error",
    "code": "human_agent_required",
    "details": { "meta_code": null, "meta_message": null, "retryable": false, "message_id": null, "sent_message_ids": [] }
  }
}

Details

Errors

  • 400 — the offending field is named in error.param: neither to nor conversation_id, a text message without text, a file type without an https media_url, reply_to on Messenger.
  • 400 invalid_idempotency_key — the Idempotency-Key header is not 8-128 characters of letters, digits, _ . : -
  • 404 conversation_not_found — this person never wrote to this account — Meta lets a business answer only people who wrote first.
  • 404 account_not_found — not an account of this project.
  • 409 account_not_api_mode — the assistant answers this account. Switch it to API mode, or send a reply typed by a person with human_agent: true.
  • 409 account_inactive — the account is switched off.
  • 409 account_reauthorization_required — the customer’s authorization is no longer valid. Mint a new connect link; the account keeps its id and history.
  • 409 human_agent_required — more than 24 hours have passed: only a reply typed by a person, marked human_agent: true, may go now (up to 7 days).
  • 409 outside_messaging_window — more than 7 days have passed since the person’s last message (or Meta refused the window). Nothing can be sent until they write again.
  • 409 recipient_unavailable — the person cannot receive messages from the account right now (they blocked it, or their profile is gone).
  • 429 meta_rate_limited — Messenger is limiting how fast this account sends; details.retryable is true — retry in a moment.
  • 502 meta_permission_error — the customer did not grant the permission the message needs; have them reconnect and accept every permission.
  • 502 meta_send_failed — Messenger refused the message, or could not be reached and nothing was sent; details.meta_code and details.meta_message say why, details.retryable whether waiting helps, details.message_id is the failed row. When a long text failed part-way, details.sent_message_ids are the parts that did go.
  • 504 meta_outcome_unknown — Messenger did not confirm the message in time: it may have been delivered. Do not resend it blindly — check the conversation (it turns "sent" when Messenger’s echo arrives); a retry with the same Idempotency-Key returns this same answer.
  • 409 idempotency_key_in_use — a request with this Idempotency-Key is still running; retry in a moment.
  • 422 idempotency_key_reused — this Idempotency-Key was used with a different request; use a new key for a new message.
  • 500 outcome_unknown — an error after the message was handed to Meta: it may have been sent — check the conversation before sending it again.
  • 429 rate_limit_exceeded — your key’s bucket is empty; honour Retry-After.
GET/api/v1/projects/{projectId}/messenger/messages/{messageId}#

Read a message

One message with its full payload — the event exactly as Messenger delivered it, or the request as it was sent.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the same object as a row of GET /messages, payload included"
}
Fields1Expand
…
the same object as a row of GET /messages, payload included

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/messages/$MESSAGE_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

Errors

  • 404 message_not_found — not a message of this project and channel.
GET/api/v1/projects/{projectId}/messenger/media/{mediaId}#

Download a file a person sent

The bytes of a picture, video, voice note or document a person sent, streamed with its content type. mediaId is the attachments[].id of an incoming message. Messenger keeps the file only for a while: download what you need to keep.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "body": "the file bytes",
  "Content-Type": "the file’s type, e.g. image/jpeg, audio/mp4, application/pdf",
  "Content-Disposition": "inline, with the file name when Meta gave one"
}
Fields3Expand
body
the file bytes
Content-Type
the file’s type, e.g. image/jpeg, audio/mp4, application/pdf
Content-Disposition
inline, with the file name when Meta gave one

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/media/$MEDIA_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" -o photo.jpg

Details

Errors

  • 400 — not a media id (it looks like <message id>.<n>).
  • 404 media_not_found — unknown id, a message you sent (only files people sent are served), an attachment without a file, or a message that was unsent or deleted since (its files went with it).
  • 410 media_unavailable — Messenger no longer serves the file (its link expired), or it is larger than the limit (25 MB).
GET/api/v1/projects/{projectId}/messenger/comments#

Read comments

Every comment written on the posts of the project’s Facebook Pages, newest first, in both modes: who wrote it, on which post, and how it was answered — publicly, privately, by whom. The account’s own comments (its answers included) are never listed.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "post_id": "string",
  "status": "\"received\" | \"replied\" | \"failed\"",
  "since": "ISO datetime",
  "until": "ISO datetime",
  "order": "\"desc\" (default) | \"asc\"",
  "include_payload": "true",
  "limit": "integer",
  "offset": "integer"
}
Fields9Expand
account_id
uuidoptional
query
post_id
stringoptional
query — the comments of one post
status
"received" | "replied" | "failed"optional
query
since
ISO datetimeoptional
query — on the moment the comment was written
until
ISO datetimeoptional
query
order
"desc" (default) | "asc"
include_payload
trueoptional
query — include each change exactly as Meta delivered it
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].account_id": "uuid",
  "data[].channel": "\"messenger\"",
  "data[].comment_id": "string",
  "data[].post_id": "string | null",
  "data[].parent_id": "string | null",
  "data[].author": "{ id, name, username: null }",
  "data[].text": "string | null",
  "data[].media_type": "string | null",
  "data[].permalink": "string | null",
  "data[].status": "\"received\" | \"replied\" | \"failed\"",
  "data[].public_reply": "{ id, text, at } | null",
  "data[].private_reply": "{ message_id, text, at } | null",
  "data[].replied_by": "\"assistant\" | \"api\" | \"person\" | null",
  "data[].can_private_reply": "boolean",
  "data[].private_reply_until": "ISO timestamp",
  "data[].error": "{ code, message } | null",
  "data[].commented_at": "ISO timestamp",
  "data[].webhook": "{ status: \"none\" | \"pending\" | \"delivered\" | \"partial\" | \"failed\", delivered_at } | null",
  "data[].created_at": "ISO timestamp",
  "data[].updated_at": "ISO timestamp",
  "data[].payload": "object",
  "page": "{ limit, offset, has_more }"
}
Fields23Expand
data[].id
uuid
the comment id the replies endpoint takes
data[].account_id
uuid
data[].channel
"messenger"
data[].comment_id
string
Facebook’s own id of the comment
data[].post_id
string | null
the post it was written under
data[].parent_id
string | null
set when it answers another comment
data[].author
{ id, name, username: null }
data[].text
string | null
data[].media_type
string | null
the post’s type (status_type)
data[].permalink
string | null
a link to the post, once known
data[].status
"received" | "replied" | "failed"
data[].public_reply
{ id, text, at } | null
the answer posted under the comment
data[].private_reply
{ message_id, text, at } | null
the private message sent to the person
data[].replied_by
"assistant" | "api" | "person" | null
data[].can_private_reply
boolean
false once the private reply went out or 7 days have passed
data[].private_reply_until
ISO timestamp
the comment’s time + 7 days
data[].error
{ code, message } | null
why the last reply failed; for the assistant: assistant_usage_limit, assistant_placeholder (its answer had a blank to fill in, like [price] — it is never posted; add that information to its instructions), assistant_failed or assistant_outcome_unknown
data[].commented_at
ISO timestamp
data[].webhook
{ status: "none" | "pending" | "delivered" | "partial" | "failed", delivered_at } | null
the delivery of the comment event (API mode)
data[].created_at
ISO timestamp
data[].updated_at
ISO timestamp
data[].payload
object
only with include_payload=true (and on one comment): the change exactly as Meta delivered it
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/comments?status=received&order=asc" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/messenger/comments/{commentId}#

Read a comment

One comment with its full payload and how it was answered.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the same object as a row of GET /comments, payload included"
}
Fields1Expand
…
the same object as a row of GET /comments, payload included

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/comments/$COMMENT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

Errors

  • 404 comment_not_found — not a comment of this project and channel.
POST/api/v1/projects/{projectId}/messenger/comments/{commentId}/replies#

Reply to a comment

Answers a comment publicly (under it, as the Facebook Page), privately (a message to the person who wrote it), or both in one call. A private reply can go ONCE per comment and within 7 days of it — Meta’s rule; when the person answers it, the conversation goes on like any other. Works in both modes. Nothing is generated: you decide the words. A text longer than Facebook takes is refused with its limit (400 text_too_long), never cut. Send an Idempotency-Key header and a retry of the same reply returns the first answer (Idempotent-Replayed: true) — the comment never gets the same answer twice.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account. Also subject to the key’s rate limit.

Request Schema

JSON type shapeExpand
{
  "Idempotency-Key": "header",
  "public_text": "string",
  "private_text": "string (optional, up to 2,000 characters",
  "(either)": "at least one of the two is required"
}
Fields4Expand
Idempotency-Key
headeroptional
recommended — as for sending a message: a retry with the same key and body returns the first answer and posts nothing again
public_text
stringoptional
up to 8,000 characters — posted under the comment
private_text
string (optional, up to 2,000 characters
one message) — sent to the person privately
(either)
at least one of the two is required

Response Schema

JSON type shapeExpand
{
  "…": "the comment, with public_reply / private_reply filled in, HTTP 201",
  "errors": "[{ which: \"public\" | \"private\", code, message }]"
}
Fields2Expand
…
the comment, with public_reply / private_reply filled in, HTTP 201
errors
[{ which: "public" | "private", code, message }]
the half that failed when the other succeeded

Code Examples

curl -X POST "$BASE/api/v1/projects/$PID/messenger/comments/$COMMENT_ID/replies" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "public_text": "Thanks! We just sent you the details by message.",
    "private_text": "Hi! The blue one is back in stock in sizes S to L. Want me to hold one for you?"
  }'
# → 201 { "id": "…", "status": "replied", "replied_by": "api",
#         "public_reply": { "id": "…", "text": "Thanks! …", "at": "…" },
#         "private_reply": { "message_id": "…", "text": "Hi! …", "at": "…" },
#         "can_private_reply": false, "errors": [] }

Details

Errors

  • 400 — neither public_text nor private_text.
  • 400 text_too_long — a text over its limit — public_text up to 8,000 characters, private_text one message (2,000 characters); error.param names it.
  • 400 invalid_idempotency_key — the Idempotency-Key header is malformed.
  • 409 private_reply_in_progress — another request is sending this comment’s private reply right now (Meta allows one); look at the comment in a moment.
  • 409 idempotency_key_in_use — a request with this Idempotency-Key is still running.
  • 422 idempotency_key_reused — this Idempotency-Key was used with a different reply.
  • 504 meta_outcome_unknown — Facebook did not confirm the reply in time: it may have been posted — check the comment before replying again.
  • 500 outcome_unknown — an error after the reply was handed to Meta: it may have been posted.
  • 404 comment_not_found — not a comment of this project and channel.
  • 409 account_inactive — the account is switched off.
  • 409 account_reauthorization_required — the authorization is no longer valid; have the customer reconnect.
  • 409 private_reply_already_sent — the comment already has its private reply (Meta allows one).
  • 409 private_reply_window_closed — more than 7 days have passed since the comment.
  • 409 recipient_unavailable — the person can no longer receive a private message from the account.
  • 429 meta_rate_limited — Facebook is limiting how fast the account replies; retry in a moment.
  • 429 rate_limit_exceeded — your key’s bucket is empty; honour Retry-After.
  • 502 meta_reply_failed — Facebook refused the reply (meta_permission_error when a permission is missing). details.errors lists each half with its code, its message and Facebook’s own number in meta_code.
POST/api/v1/projects/{projectId}/messenger/webhooks#

Register a webhook

Where the messages, comments and statuses of the project’s API-mode Messenger accounts are delivered. A hook may listen to every account of the project or to one. It is a project webhook — same signature, retries and auto-disable rules as the budget hooks — and its secret is returned once, here. Idempotent: registering the same url on the same scope again, when the hook already listens to every event asked, answers that hook — 200, reused: true, no secret — instead of a second one.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "url": "https url",
  "account_id": "uuid | null",
  "events": "[\"messenger.message.received\", \"messenger.message.status\", \"messenger.message.echo\", \"messenger.message.deleted\", \"messenger.comment.received\"]"
}
Fields3Expand
url
https urlrequired
public host; private and loopback addresses are refused
account_id
uuid | nulloptional
deliver only this account’s events; omit or null for every account of the project
events
["messenger.message.received", "messenger.message.status", "messenger.message.echo", "messenger.message.deleted", "messenger.comment.received"]optional
default ["messenger.message.received", "messenger.comment.received"]

Response Schema

JSON type shapeExpand
{
  "id": "uuid",
  "url": "string",
  "account_id": "uuid | null",
  "events": "string[]",
  "is_active": "boolean",
  "secret": "hex string",
  "reused": "boolean",
  "created_at": "ISO timestamp",
  "updated_at": "ISO timestamp",
  "last_delivery_at": "ISO timestamp | null",
  "failure_count": "integer"
}
Fields11Expand
id
uuid
url
string
account_id
uuid | null
events
string[]
is_active
boolean
secret
hex string
shown ONCE, on a 201 only; check every delivery’s signature with it
reused
boolean
true: the existing hook was answered (200, no secret); false: created (201)
created_at
ISO timestamp
updated_at
ISO timestamp
last_delivery_at
ISO timestamp | null
failure_count
integer
consecutive failed deliveries; the hook is disabled at 20

Code Examples

curl -X POST "$BASE/api/v1/projects/$PID/messenger/webhooks" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://acme.example/messenger/inbound",
    "account_id": "'$ACCOUNT_ID'",
    "events": ["messenger.message.received", "messenger.comment.received", "messenger.message.echo"]
  }'
# → 201 { "id": "…", "secret": "0f3a…", … }   ← store the secret now

Details

Errors

  • 400 — an unknown event (another channel’s too), or a url that is not public https.
  • 404 account_not_found — account_id is not an account of this project.
GET/api/v1/projects/{projectId}/messenger/webhooks#

List webhooks

The project’s Messenger webhooks, without secrets. Budget hooks and other channels’ hooks of the same project are not shown here.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "include_disabled": "true"
}
Fields2Expand
account_id
uuidoptional
query — the hooks that would fire for this account: its own and the project-wide ones
include_disabled
trueoptional
query

Response Schema

JSON type shapeExpand
{
  "data[]": "the webhook objects, without secrets"
}
Fields1Expand
data[]
the webhook objects, without secrets

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/webhooks" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/messenger/webhooks/{webhookId}#

Read a webhook

One Messenger webhook, without its secret. A hook of another channel, or a budget hook, is 404 here.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the webhook object, without its secret"
}
Fields1Expand
…
the webhook object, without its secret

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

Errors

  • 404 webhook_not_found — not a webhook of this channel on this project; an id that is not a UUID is answered the same way.
PUT/api/v1/projects/{projectId}/messenger/webhooks/{webhookId}#

Update a webhook

Change the url, the events, the account it listens to, switch it on or off, or rotate its secret (the new one is returned once, and the failure count starts again). Switching it back on — also after the auto-disable — restarts its failure count. Every change is written to the project’s audit log.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "url": "https url",
  "account_id": "uuid | null",
  "events": "string[]",
  "is_active": "boolean",
  "rotate_secret": "true"
}
Fields5Expand
url
https urloptional
account_id
uuid | nulloptional
null makes it project-wide
events
string[]optional
this channel’s events only
is_active
booleanoptional
rotate_secret
trueoptional
mint a new secret

Response Schema

JSON type shapeExpand
{
  "…": "the webhook object; secret only when rotated"
}
Fields1Expand
…
the webhook object; secret only when rotated

Code Examples

curl -X PUT "$BASE/api/v1/projects/$PID/messenger/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "rotate_secret": true }'
# → 200 { …, "secret": "new hex" }

Details

Errors

  • 400 — an empty patch or a body with none of the fields, an unknown event, a url that is not public https.
  • 404 webhook_not_found — not a webhook of this channel on this project; an id that is not a UUID is answered the same way.
DELETE/api/v1/projects/{projectId}/messenger/webhooks/{webhookId}#

Deactivate a webhook

Stops deliveries to it. The hook and its delivery log are kept; a PUT with is_active true switches it back on.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Code Examples

curl -X DELETE "$BASE/api/v1/projects/$PID/messenger/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → 204

Details

Errors

  • 410 — it was already inactive.
  • 404 webhook_not_found — not a webhook of this channel on this project; an id that is not a UUID is answered the same way.
POST/api/v1/projects/{projectId}/messenger/webhooks/{webhookId}/test#

Test a webhook

Sends a sample messenger.message.received event, signed like a real one, with data.test = true and a real account of the project — one attempt with the same 8-second timeout as a real delivery, so the answer says what your endpoint did right now. A failing test never counts toward the auto-disable.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "delivered": "boolean",
  "attempts": "integer",
  "event_id": "uuid",
  "response_status": "integer | null",
  "error": "string | null"
}
Fields5Expand
delivered
boolean
your endpoint answered 2xx
attempts
integer
1
event_id
uuid
the id of the sample event
response_status
integer | null
the HTTP status your endpoint answered
error
string | null
http_<status> | timeout | fetch_error | url_<reason>

Code Examples

curl -X POST "$BASE/api/v1/projects/$PID/messenger/webhooks/$WEBHOOK_ID/test" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → 202 { "delivered": true, "attempts": 1, "event_id": "…" }

Details

Errors

  • 404 webhook_not_found — not an active webhook of this channel on this project; an id that is not a UUID is answered the same way.
GET/api/v1/projects/{projectId}/messenger/traffic#

Traffic of a project

Messages and comments per day on one project — received, sent, failed — zero-filled over the window, plus how many people wrote and how many accounts are active. A handful of grouped queries whatever the volume; the Partner Console draws its chart from it.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "from": "string",
  "to": "string",
  "group_by": "\"day\" (default) | \"account\"",
  "account_id": "uuid"
}
Fields4Expand
from
stringoptional
ISO datetime or YYYY-MM-DD. Defaults to 30 days before to.
to
stringoptional
ISO datetime or YYYY-MM-DD (a bare date covers its whole day). Defaults to now. The window may not exceed 90 days.
group_by
"day" (default) | "account"
"account" adds a per-account breakdown
account_id
uuidoptional
narrow the report to one account

Response Schema

JSON type shapeExpand
{
  "project_id": "uuid",
  "window": {
    "from": "ISO",
    "to": "ISO"
  },
  "channel": "\"messenger\"",
  "group_by": "string",
  "totals": {
    "inbound": "integer",
    "outbound": "integer",
    "total": "integer",
    "failed": "integer",
    "comments": "integer",
    "active_conversations": "integer",
    "accounts": "integer"
  },
  "series": [
    {
      "bucket": "YYYY-MM-DD (UTC)",
      "inbound": "integer",
      "outbound": "integer",
      "total": "integer",
      "failed": "integer",
      "comments": "integer"
    }
  ],
  "by_account": [
    {
      "account_id": "uuid",
      "project_id": "uuid",
      "name": "string | null",
      "display_name": "string | null",
      "username": "string | null",
      "inbound": "integer",
      "outbound": "integer",
      "total": "integer",
      "failed": "integer",
      "comments": "integer"
    }
  ]
}
Fields32Expand
project_id
uuid
window
object
object — fields below
from
ISO
to
ISO
channel
"messenger"
group_by
string
totals
object
object — fields below
inbound
integer
messages received
outbound
integer
messages sent (by the assistant, your application, people or workflows)
total
integer
failed
integer
sends that failed
comments
integer
comments received
active_conversations
integer
people who wrote in the window
accounts
integer
active accounts
series
array
array — fields below
bucket
YYYY-MM-DD (UTC)
inbound
integer
outbound
integer
total
integer
failed
integer
comments
integer
by_account
array
array — fields below
account_id
uuid
project_id
uuid
name
string | null
display_name
string | null
username
string | null
inbound
integer
outbound
integer
total
integer
failed
integer
comments
integer

Code Examples

curl "$BASE/api/v1/projects/$PID/messenger/traffic?from=2026-11-01&to=2026-11-30&group_by=account" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/messenger/accounts#

Every account, all projects

Every Facebook Page connected to any of your projects, in one paged list with its project. The account-wide counterpart of the per-project list — one call for a thousand projects, never one per project.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "mode": "\"api\" | \"assistant\"",
  "include_inactive": "true",
  "project_ids": "string",
  "limit": "integer",
  "offset": "integer"
}
Fields5Expand
mode
"api" | "assistant"optional
include_inactive
trueoptional
project_ids
stringoptional
comma-separated project UUIDs (at most 1000); ids you do not own simply do not match
limit
integeroptional
1..200, default 50
offset
integeroptional
default 0

Response Schema

JSON type shapeExpand
{
  "data[]": "the account object (without webhook_count), plus project_name",
  "page": "{ limit, offset, has_more }"
}
Fields2Expand
data[]
the account object (without webhook_count), plus project_name
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/messenger/accounts?mode=api&limit=100" \
  -H "Authorization: Bearer $ADMIN_KEY"
PUT/api/v1/messenger/accounts#

Bulk mode, active and comment replies

Set who answers, whether accounts are active, and what the assistant does with comments — on every Messenger account of your projects in one call, or on a selection by project and/or account. One transaction; one audit row (marked bulk) per account whose stored value actually changes; a re-apply writes nothing. Switching on reaches only accounts that still hold their authorization, and leaves untouched — listed in skipped — an account another connection already holds (one active connection per Facebook Page), or a second copy of one in the selection.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "mode": "\"api\" | \"assistant\"",
  "is_active": "boolean",
  "comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\"",
  "project_ids": "string[]",
  "account_ids": "string[]"
}
Fields5Expand
mode
"api" | "assistant"optional
at least one of mode / is_active / comment_reply_mode is required
is_active
booleanoptional
comment_reply_mode
"off" | "public" | "private" | "both"optional
project_ids
string[]optional
1..1000 project UUIDs; absent = every project of the account
account_ids
string[]optional
1..1000 account ids, narrowing the selection further

Response Schema

JSON type shapeExpand
{
  "matched": "integer",
  "updated": "integer",
  "mode": "echoed when sent",
  "is_active": "echoed when sent",
  "comment_reply_mode": "echoed when sent",
  "skipped": "[{ id, reason: \"account_in_use\" }]"
}
Fields6Expand
matched
integer
accounts in scope
updated
integer
accounts whose stored value changed
mode
echoed when sent
is_active
echoed when sent
comment_reply_mode
echoed when sent
skipped
[{ id, reason: "account_in_use" }]
always present; the accounts left untouched

Code Examples

curl -X PUT "$BASE/api/v1/messenger/accounts" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "assistant", "comment_reply_mode": "both", "project_ids": ["'"$PID"'"] }'
{ "matched": 3, "updated": 2, "mode": "assistant", "comment_reply_mode": "both", "skipped": [] }

Details

Errors

  • 409 account_in_use — an account in the selection was switched on concurrently by another connection; send the request again.
GET/api/v1/messenger/traffic#

Traffic, all projects

The same report as the per-project traffic, across every project you own (or a project_ids selection), with an optional per-project or per-account breakdown. Every figure comes from grouped queries — it costs the same for one project as for a thousand.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "from": "string",
  "to": "string",
  "group_by": "\"day\" (default) | \"project\" | \"account\"",
  "project_ids": "string",
  "account_id": "uuid"
}
Fields5Expand
from
stringoptional
ISO datetime or YYYY-MM-DD
to
stringoptional
at most 90 days after from
group_by
"day" (default) | "project" | "account"
project_ids
stringoptional
comma-separated project UUIDs (at most 1000)
account_id
uuidoptional
narrow the report to one account

Response Schema

JSON type shapeExpand
{
  "projects": "integer",
  "window": {
    "from": "ISO",
    "to": "ISO"
  },
  "channel": "\"messenger\"",
  "group_by": "string",
  "totals": "{ inbound, outbound, total, failed, comments, active_conversations, accounts }",
  "series": "[{ bucket, inbound, outbound, total, failed, comments }]",
  "by_project": "[{ project_id, name, inbound, outbound, total, failed, comments }]",
  "by_account": "[{ account_id, project_id, name, display_name, username, inbound, outbound, total, failed, comments }]"
}
Fields10Expand
projects
integer
projects in scope
window
object
object — fields below
from
ISO
to
ISO
channel
"messenger"
group_by
string
totals
{ inbound, outbound, total, failed, comments, active_conversations, accounts }
series
[{ bucket, inbound, outbound, total, failed, comments }]
by_project
[{ project_id, name, inbound, outbound, total, failed, comments }]
with group_by=project
by_account
[{ account_id, project_id, name, display_name, username, inbound, outbound, total, failed, comments }]
with group_by=account

Code Examples

curl "$BASE/api/v1/messenger/traffic?group_by=project" \
  -H "Authorization: Bearer $ADMIN_KEY"
POST/api/v1/messenger/webhooks#

Webhook on every project

Register one webhook URL on every project you own (or a project_ids selection) in a single call. One secret is minted for the whole batch and returned once, so an application that receives every customer’s events at one endpoint checks them all with one key. A project that already has an active project-wide hook on that URL listening to every event asked is left alone and reported as reused; a hook there listening to fewer events gets a new one beside it. Concurrent calls make one hook per project.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "url": "string",
  "events": "string[]",
  "project_ids": "string[]"
}
Fields3Expand
url
stringrequired
https URL; private, loopback and link-local addresses are refused
events
string[]optional
default ["messenger.message.received", "messenger.comment.received"]
project_ids
string[]optional
1..1000 project UUIDs; absent = every project of the account

Response Schema

JSON type shapeExpand
{
  "secret": "string | null",
  "created": "integer",
  "reused": "integer",
  "webhooks": "[{ id, project_id, url, events, is_active, reused, created_at }]"
}
Fields4Expand
secret
string | null
the one secret of every hook created, shown ONCE; null when nothing was created
created
integer
reused
integer
webhooks
[{ id, project_id, url, events, is_active, reused, created_at }]

Code Examples

curl -X POST "$BASE/api/v1/messenger/webhooks" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://acme.example/messenger/inbound", "events": ["messenger.message.received", "messenger.comment.received"] }'
Guide

Webhook payload & signature

Every delivery is a JSON POST with the headers X-Ainvented-Event, X-Ainvented-Delivery (the event id) and X-Ainvented-Signature: sha256= followed by the hex HMAC-SHA256 of the raw body under your webhook's secret. Verify it before trusting a payload. Deliveries start right after Meta's own notification has been stored and acknowledged; answer with any 2xx within 8 seconds — anything else is retried once, and the message or comment is marked webhook.status = "failed" for you to read back ("partial" when some of your hooks accepted it and others did not). Deliveries are at-least-once: the same event delivered twice — a duplicate from Meta, or a delivery a restart cut, which is sent again within a few minutes — carries the same X-Ainvented-Delivery, so drop ids you have already processed.

  • messenger.message.received — data.message (with its payload), data.account, data.conversation.
  • messenger.message.status — data.status and the outbound data.message, already updated, for messages sent through the API or by a person from the console. Messenger reports delivered and read.
  • messenger.message.echo — a reply typed outside Ainvented (Meta's own inbox, the Page app, another tool), stored with author: "page_inbox"; data.message, data.account, data.conversation.
  • messenger.message.deleted — the person unsent a message. Its content is already gone from Ainvented: data.message is that message with type: "unsent", text: null, no attachments and a null payload (type: "deleted" when your team had already deleted it in the inbox), so match it by data.message.id or message_id and remove your own copy; with data.account and data.conversation. Not among a new webhook's default events: name it in events to receive it.
  • messenger.comment.received — data.comment (with its payload) and data.account.
messenger.message.received
{
  "id": "3f6c1a2e-…",
  "event": "messenger.message.received",
  "occurred_at": "2026-11-10T10:15:02.114Z",
  "project_id": "…",
  "data": {
    "message": {
      "id": "…",
      "account_id": "…",
      "conversation_id": "…",
      "channel": "messenger",
      "direction": "inbound",
      "message_id": "m_AbC1dE2fG3…",
      "author": "customer",
      "from": "6712345678901234",
      "to": "104857600123456",
      "type": "image",
      "text": "is this the blue one?",
      "attachments": [
        {
          "id": "…message id….0",
          "type": "image",
          "url": "https://…",
          "mime_type": null,
          "name": null
        }
      ],
      "tag": null,
      "reply_to": null,
      "status": "received",
      "error": null,
      "sent_at": "2026-11-10T10:15:00.000Z",
      "delivered_at": null,
      "read_at": null,
      "webhook": {
        "status": "pending",
        "delivered_at": null
      },
      "api_key_id": null,
      "created_at": "2026-11-10T10:15:02.010Z",
      "payload": {
        "sender": {
          "id": "6712345678901234"
        },
        "recipient": {
          "id": "104857600123456"
        },
        "timestamp": 1794305700000,
        "message": {
          "mid": "m_AbC1dE2fG3…",
          "text": "is this the blue one?",
          "attachments": [
            {
              "type": "image",
              "payload": {
                "url": "https://…"
              }
            }
          ]
        }
      }
    },
    "account": {
      "id": "…",
      "channel": "messenger",
      "name": "Acme Support",
      "external_id": "104857600123456",
      "display_name": "Acme",
      "username": null
    },
    "conversation": {
      "id": "…",
      "participant_id": "6712345678901234",
      "name": "Ana",
      "inbound_count": 3,
      "outbound_count": 2,
      "window": {
        "state": "standard",
        "standard_until": "2026-11-11T10:15:00.000Z",
        "human_agent_until": "2026-11-17T10:15:00.000Z"
      },
      "assistant": {
        "state": "active",
        "paused_until": null
      },
      "…": "…"
    }
  }
}
messenger.comment.received
{
  "id": "8a1d…",
  "event": "messenger.comment.received",
  "occurred_at": "2026-11-10T11:02:40.000Z",
  "project_id": "…",
  "data": {
    "comment": {
      "id": "…",
      "account_id": "…",
      "channel": "messenger",
      "comment_id": "104857600123456_998877665544",
      "post_id": "104857600123456_112233445566",
      "parent_id": null,
      "author": {
        "id": "5512345678901234",
        "name": "Ana Pérez",
        "username": null
      },
      "text": "Do you ship to Bogotá?",
      "media_type": "added_photos",
      "permalink": null,
      "status": "received",
      "public_reply": null,
      "private_reply": null,
      "replied_by": null,
      "can_private_reply": true,
      "private_reply_until": "2026-11-17T11:02:38.000Z",
      "error": null,
      "commented_at": "2026-11-10T11:02:38.000Z",
      "webhook": {
        "status": "pending",
        "delivered_at": null
      },
      "created_at": "2026-11-10T11:02:40.000Z",
      "updated_at": "2026-11-10T11:02:40.000Z",
      "payload": {
        "field": "feed",
        "value": {
          "…": "exactly as Meta delivered it"
        }
      }
    },
    "account": {
      "id": "…",
      "channel": "messenger",
      "name": "Acme Support",
      "external_id": "104857600123456",
      "display_name": "Acme",
      "username": null
    }
  }
}
Node — verify a delivery
# Node — verify a delivery
const crypto = require('crypto');
const expected = 'sha256=' + crypto.createHmac('sha256', WEBHOOK_SECRET).update(rawBody).digest('hex');
const ok = expected.length === signature.length &&
  crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature));
Guide

What your customer goes through

The page you send them is hosted by Ainvented and needs no account. They sign in with Facebook, in Meta’s own window, and choose the Page to share. If they share more than one, the page asks which one to connect. When they are done they land on your return_url, or on a success card.

Limits worth designing around

  • One account, one project. An account already active on another project is refused until it is disconnected there.
  • Reconnecting is the same call. The same account brought back to the same project is refreshed in place: same id, same history.
  • Their own Page. The person signing in must be able to manage the Page's messages.
  • The authorization does not expire on a schedule. It stops only if the customer removes access in Meta's settings; the account then reads needs_reconnect: true and sends answer account_reauthorization_required.
  • Disconnecting keeps the history. DELETE /messenger/accounts/{accountId} stops the messages and forgets the authorization; conversations, messages and comments stay readable.
Reference · 27 endpoints

Instagram

Attach a customer's Instagram professional account to one of your projects. You call one endpoint, get back a URL and hand it to your customer — they sign in with Instagram or with Facebook, in Meta’s own window, and choose the account to share — no Facebook Page is needed. Neither you nor they ever see an access token; Ainvented obtains it from Meta server-side and stores it encrypted.

Once connected, the account appears on the project with a mode: either the project's assistant answers its messages (and, if you choose, its comments) by itself, or every message and comment is handed to your application through a webhook and you answer through the API, with nothing generated in between. Either way every message is stored, a person can step in from the console or through this API, and the traffic is readable per project or across all of them. All of these endpoints are reserved for reseller accounts and take an Admin API key.

In this section
  1. GuideAssistant vs API mode
  2. GuideThe messaging windows
  3. GuideComments
  4. POSTCreate a connect link/api/v1/projects/{projectId}/instagram/connect
  5. GETCheck connect links/api/v1/projects/{projectId}/instagram/connect
  6. GETList accounts/api/v1/projects/{projectId}/instagram/accounts
  7. GETRead an account/api/v1/projects/{projectId}/instagram/accounts/{accountId}
  8. PUTUpdate an account/api/v1/projects/{projectId}/instagram/accounts/{accountId}
  9. DELETEDisconnect an account/api/v1/projects/{projectId}/instagram/accounts/{accountId}
  10. GETWho wrote in/api/v1/projects/{projectId}/instagram/conversations
  11. GETRead a conversation/api/v1/projects/{projectId}/instagram/conversations/{conversationId}
  12. PUTPause or resume the assistant/api/v1/projects/{projectId}/instagram/conversations/{conversationId}
  13. GETRead messages/api/v1/projects/{projectId}/instagram/messages
  14. POSTSend a message/api/v1/projects/{projectId}/instagram/messages
  15. GETRead a message/api/v1/projects/{projectId}/instagram/messages/{messageId}
  16. GETDownload a file/api/v1/projects/{projectId}/instagram/media/{mediaId}
  17. GETRead comments/api/v1/projects/{projectId}/instagram/comments
  18. GETRead a comment/api/v1/projects/{projectId}/instagram/comments/{commentId}
  19. POSTReply to a comment/api/v1/projects/{projectId}/instagram/comments/{commentId}/replies
  20. POSTRegister an Instagram webhook/api/v1/projects/{projectId}/instagram/webhooks
  21. GETList webhooks/api/v1/projects/{projectId}/instagram/webhooks
  22. GETRead a webhook/api/v1/projects/{projectId}/instagram/webhooks/{webhookId}
  23. PUTUpdate a webhook/api/v1/projects/{projectId}/instagram/webhooks/{webhookId}
  24. DELETEDeactivate a webhook/api/v1/projects/{projectId}/instagram/webhooks/{webhookId}
  25. POSTTest a webhook/api/v1/projects/{projectId}/instagram/webhooks/{webhookId}/test
  26. GETTraffic of a project/api/v1/projects/{projectId}/instagram/traffic
  27. GETEvery account, all projects/api/v1/instagram/accounts
  28. PUTBulk mode / active / comments/api/v1/instagram/accounts
  29. GETTraffic, all projects/api/v1/instagram/traffic
  30. POSTWebhook on every project/api/v1/instagram/webhooks
  31. GuideWebhook payload & signature
  32. GuideWhat your customer sees
Guide

Assistant mode vs API mode

mode: "assistant" (default)mode: "api"
Who answersThe project's assistant, right away, inside Meta's 24-hour window. Same as connecting from the AI Chat view.Your application. Nothing is generated: the message is stored, delivered to your webhooks, and you reply — or not — with POST /instagram/messages.
CommentsWhat the account chose in comment_reply_mode: nothing (the default), a public answer, a private message, or both.Each new comment reaches your webhooks as instagram.comment.received; you answer with POST /instagram/comments/{commentId}/replies.
What it costs youEach message or comment the assistant answers is a priced assistant turn on the project, like a chat completion.No tokens are spent on the project, for anything received or sent. Instagram itself charges nothing per message.
HistoryBoth modes keep every message, both ways, in GET /instagram/conversations and GET /instagram/messages — the assistant's answers too, so a person can read a conversation and step in.
SwitchingAny time, without reconnecting: PUT /instagram/accounts/{accountId} with the new mode.
Guide

The messaging windows

Instagram only lets a business answer people who wrote first, and only for a while. Every conversation says where it stands in window.state, and every send is checked against it before anything leaves.

  • Within 24 hours of the person's last message (standard): anyone may answer — the assistant, your application, a person.
  • From 24 hours to 7 days (human_agent): only a reply typed by a person, sent with human_agent: true. It travels with Meta's Human Agent tag. The assistant stays silent; any other send is refused with human_agent_required.
  • After 7 days (closed): nothing can be sent until the person writes again (outside_messaging_window).
  • What opens a window: a message or a tapped button from the person. A reaction does not.
  • A person takes over. When a person replies — from the console, through this API with human_agent, or in Meta's own inbox — the assistant pauses in that conversation for 24 hours. PUT /instagram/conversations/{conversationId} pauses or resumes it at will.
  • The assistant says it is one. Its first reply of a conversation, and its first after a day without one, begins with the account's automation_notice, as Meta asks. Change it or switch it off with PUT /instagram/accounts/{accountId}.
human_agent is for people

Meta reviews how the Human Agent tag is used. Send human_agent: true only on words a person typed; marking automated messages with it can get the account's messaging restricted.

Guide

Comments: public, private or both

Every new comment on the posts of a connected Instagram professional account is stored, in both modes, and readable in GET /instagram/comments. The account's own comments — its answers included — are never stored or answered.

  • Assistant mode does what comment_reply_mode says: off (the default) nothing; public an answer under the comment, as the account; private a message to the person; both the same answer both ways. One assistant turn per comment, priced like a message.
  • API mode delivers instagram.comment.received to your webhooks; answer with POST /instagram/comments/{commentId}/replies, publicly, privately or both.
  • One private reply per comment, within 7 days of it — Meta's rule, checked before anything is sent (can_private_reply). When the person answers it, the conversation goes on under the usual windows.
  • The account must be public for its comments to be delivered at all.
  • Instagram answers top-level comments: a public reply to a reply lands under the top-level comment. Comments on a live video arrive with media_type LIVE and can only be answered privately, while the broadcast lasts.
POST/api/v1/projects/{projectId}/instagram/connect#

Create a connect link

Mints a one-shot URL that walks your customer through Meta’s login and attaches their Instagram professional account to this project. They sign in with Instagram or with Facebook, in Meta’s own window, and choose the account to share — no Facebook Page is needed. You get a URL and hand it over — no SDK, no Meta app of your own; neither you nor they ever see an access token. The link is single-use and expires after 7 days; a customer whose attempt failed (they cancelled in Meta’s window, or shared nothing) can try again on the same link until then. If the Instagram professional account they pick is already live on another of your projects, the page offers to move it here — without naming that project to your customer; an account connected to someone else’s project is refused. The account it creates answers through the project’s assistant unless you ask for API mode.

Authentication

Bearer <admin_api_key> — must be an account-wide Admin key (no project binding), must own the project, and the account must be a reseller.

Request Schema

JSON type shapeExpand
{
  "connector_name": "string",
  "return_url": "url",
  "mode": "\"assistant\" | \"api\"",
  "comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\""
}
Fields4Expand
connector_name
stringoptional
1..100 chars — label for the account; omit it and the Instagram professional account’s own name is used. On a reconnect, a name given here replaces the old one
return_url
urloptional
where the customer lands after connecting. Must be http or https; other schemes are a 400. Omit it and they stay on a success card.
mode
"assistant" | "api"optional
default "assistant" — who answers. "assistant": the project’s assistant replies by itself; "api": messages and comments go to your webhooks and you reply through this API. Applied to the account the link connects — also when it reconnects one this project already has, so name the mode you want kept.
comment_reply_mode
"off" | "public" | "private" | "both"optional
default "off" — what the assistant does with a new comment on the account’s posts: a public answer under it, a private message to the person, or both — a short public answer plus the full one in private. Read only in assistant mode. Applied on a reconnect too, like mode.

Response Schema

JSON type shapeExpand
{
  "connect_url": "the URL to hand your customer",
  "connect_token": "the token embedded in that URL; correlate with the list endpoint on it",
  "project_id": "uuid",
  "channel": "\"instagram\"",
  "status": "\"pending\" on creation",
  "connector_name": "string | null",
  "return_url": "string | null",
  "mode": "\"assistant\" | \"api\"",
  "comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\"",
  "expires_at": "ISO timestamp"
}
Fields10Expand
connect_url
the URL to hand your customer
https://<app>/connect/instagram/<token>
connect_token
the token embedded in that URL; correlate with the list endpoint on it
project_id
uuid
channel
"instagram"
status
"pending" on creation
connector_name
string | null
echoed back
return_url
string | null
echoed back
mode
"assistant" | "api"
the mode the account will be created in
comment_reply_mode
"off" | "public" | "private" | "both"
expires_at
ISO timestamp
after this the link is dead; mint another

Code Examples

Send the returned connect_url however you like: an email, a button in your own dashboard, a QR code. Your customer needs no Ainvented account.

curl -X POST "$BASE/api/v1/projects/$PID/instagram/connect" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "connector_name": "Acme Support",
    "mode": "api",
    "comment_reply_mode": "off",
    "return_url": "https://acme.example/settings/instagram?done=1"
  }'
# → 201 { "connect_url": "https://ainvented.com/connect/instagram/DlhaNJ_Jyaf...",
#         "connect_token": "DlhaNJ_Jyaf...", "status": "pending", "mode": "api",
#         "expires_at": "2026-11-17T20:17:38.262Z" }

Details

Errors

  • 403 admin_key_required — the key is bound to a project. Everything under /v1/projects/** is account management and needs an Admin key.
  • 403 instagram_not_enabled — the account is not approved for the Instagram endpoints. Every route under /instagram/ answers this for a non-reseller account.
  • 403 project_disabled — the project was deleted (reads stay allowed, writes do not).
  • 400 — a bad project id, a return_url that is not http(s), a mode or comment_reply_mode outside the listed values.
  • 503 instagram_not_configured — Instagram onboarding is not switched on for this deployment. Never a client bug; retry later.
GET/api/v1/projects/{projectId}/instagram/connect#

Check connect links

Lists the connect links issued for this project, newest first, so you can tell whether a customer finished. Poll it after handing a link over, or read it when your customer comes back to your app.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "status": "\"pending\" | \"selecting\" | \"completed\" | \"failed\" | \"expired\"",
  "limit": "integer",
  "offset": "integer"
}
Fields3Expand
status
"pending" | "selecting" | "completed" | "failed" | "expired"optional
query — filter. "selecting": the customer signed in and is choosing which account to connect. "failed": the last attempt failed (`error_code` says why); the link works until it expires
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].connect_token": "the token from the POST response",
  "data[].status": "\"pending\" | \"selecting\" | \"completed\" | \"failed\" | \"expired\"",
  "data[].connector_id": "uuid | null",
  "data[].connector_name": "string | null",
  "data[].mode": "\"assistant\" | \"api\"",
  "data[].comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\"",
  "data[].via": "\"connect_link\" | \"ai_chat\"",
  "data[].error_code": "string | null",
  "data[].error_message": "string | null",
  "data[].created_at": "ISO timestamp",
  "data[].expires_at": "ISO timestamp",
  "data[].completed_at": "ISO timestamp | null",
  "page": "{ limit, offset, has_more }"
}
Fields13Expand
data[].connect_token
the token from the POST response
correlate on this
data[].status
"pending" | "selecting" | "completed" | "failed" | "expired"
data[].connector_id
uuid | null
the account now live on the project, once status is "completed"
data[].connector_name
string | null
data[].mode
"assistant" | "api"
data[].comment_reply_mode
"off" | "public" | "private" | "both"
data[].via
"connect_link" | "ai_chat"
data[].error_code
string | null
cancelled | account_in_use | account_in_use_elsewhere | meta_login_failed | meta_accounts_unreadable | no_account_shared | subscription_failed | project_unavailable | server_error
data[].error_message
string | null
why the last attempt failed, in a sentence; the link still works, the customer can retry
data[].created_at
ISO timestamp
data[].expires_at
ISO timestamp
data[].completed_at
ISO timestamp | null
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/connect?status=completed" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

The listing never returns connect_url again

A link is a bearer capability — whoever holds it can attach an account to that project — so it is issued once and never re-exposed. To get another, POST again.

GET/api/v1/projects/{projectId}/instagram/accounts#

List connected accounts

The Instagram professional accounts attached to this project, with their mode, what the assistant does with comments, how many people wrote and how many of your webhooks fire for each. Inactive accounts are hidden unless asked for.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account. Same for every endpoint below.

Request Schema

JSON type shapeExpand
{
  "mode": "\"api\" | \"assistant\"",
  "include_inactive": "true"
}
Fields2Expand
mode
"api" | "assistant"optional
query — only accounts in that mode
include_inactive
trueoptional
query — also list switched-off and disconnected accounts

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].project_id": "uuid",
  "data[].channel": "\"instagram\"",
  "data[].name": "string",
  "data[].mode": "\"assistant\" | \"api\"",
  "data[].external_id": "string",
  "data[].display_name": "string | null",
  "data[].username": "string | null",
  "data[].comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\"",
  "data[].automation_notice": "string",
  "data[].business_id": "string | null",
  "data[].onboarded_via": "\"connect_link\" | \"ai_chat\" | null",
  "data[].is_active": "boolean",
  "data[].token_expires_at": "ISO timestamp | null",
  "data[].needs_reconnect": "boolean",
  "data[].connected_at": "ISO timestamp",
  "data[].updated_at": "ISO timestamp",
  "data[].conversation_count": "integer",
  "data[].last_inbound_at": "ISO timestamp | null",
  "data[].comment_count": "integer",
  "data[].webhook_count": "integer"
}
Fields21Expand
data[].id
uuid
the account_id used by every other endpoint
data[].project_id
uuid
data[].channel
"instagram"
data[].name
string
your label for the account
data[].mode
"assistant" | "api"
who answers its messages
data[].external_id
string
the Instagram professional account’s own id on Instagram
data[].display_name
string | null
the Instagram professional account’s name
data[].username
string | null
the @username, without the @
data[].comment_reply_mode
"off" | "public" | "private" | "both"
what the assistant does with a new comment (assistant mode only)
data[].automation_notice
string
the line put before the assistant’s first reply of a conversation (and before its private reply to a comment); by default "🤖 Asistente automático · Automated assistant"; "" when switched off
data[].business_id
string | null
the customer’s business portfolio id
data[].onboarded_via
"connect_link" | "ai_chat" | null
data[].is_active
boolean
data[].token_expires_at
ISO timestamp | null
null means the authorization does not expire on a schedule
data[].needs_reconnect
boolean
true once the authorization stopped working (or the account was disconnected); mint a new connect link
data[].connected_at
ISO timestamp
data[].updated_at
ISO timestamp
data[].conversation_count
integer
people who have written to this account
data[].last_inbound_at
ISO timestamp | null
data[].comment_count
integer
comments received on the account’s posts
data[].webhook_count
integer
your active instagram.* webhooks that fire for this account

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/accounts?mode=api" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/instagram/accounts/{accountId}#

Read an account

One connected account, same fields as the listing. An account of another project answers 404 account_not_found — an account id never resolves across projects.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the same object as one row of the listing"
}
Fields1Expand
…
the same object as one row of the listing

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/accounts/$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"
PUT/api/v1/projects/{projectId}/instagram/accounts/{accountId}#

Update an account

Rename an account, switch who answers it, choose what the assistant does with comments, change or switch off the automated-assistant notice, or switch the account off and on. Switching to API mode is how an account connected from the AI Chat view stops answering by itself and starts reaching your webhooks — the customer does not reconnect. Every change is written to the project’s audit log.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "mode": "\"api\" | \"assistant\"",
  "is_active": "boolean",
  "comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\"",
  "automation_notice": "string | null"
}
Fields5Expand
name
stringoptional
1..100 chars
mode
"api" | "assistant"optional
is_active
booleanoptional
false stops both directions: incoming messages are ignored and sends are refused with 409 account_inactive. true brings back an account that still holds its authorization
comment_reply_mode
"off" | "public" | "private" | "both"optional
automation_notice
string | nulloptional
up to 300 chars — the line put before the assistant’s first reply of a conversation (and again after a day without one). "" switches it off; null restores the default notice

Response Schema

JSON type shapeExpand
{
  "…": "the updated account, same shape as the listing"
}
Fields1Expand
…
the updated account, same shape as the listing

Code Examples

curl -X PUT "$BASE/api/v1/projects/$PID/instagram/accounts/$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "api" }'
curl -X PUT "$BASE/api/v1/projects/$PID/instagram/accounts/$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "assistant", "comment_reply_mode": "private" }'

Details

Errors

  • 400 — nothing to update, or a value outside the listed ones.
  • 409 account_reauthorization_required — is_active: true on an account that was disconnected: it holds no authorization any more. Mint a connect link.
  • 409 account_in_use — the same Instagram professional account is active on another connection; switch that one off first.
  • 404 account_not_found — not an account of this project.
  • 403 project_disabled — the project was deleted.
DELETE/api/v1/projects/{projectId}/instagram/accounts/{accountId}#

Disconnect an account

Stops Instagram from delivering this account’s messages and comments to us, switches the account off and forgets its authorization. Its conversations, messages and comments stay readable. To bring it back, the customer connects it again through a new link — the same Instagram professional account reconnected to the same project keeps its id and its history.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the account, now with is_active false and needs_reconnect true",
  "unsubscribed": "boolean"
}
Fields2Expand
…
the account, now with is_active false and needs_reconnect true
unsubscribed
boolean
whether Instagram confirmed it stopped delivering (false when it could not be reached; nothing is processed for a disconnected account either way). Also false when the same Instagram professional account is active on another connection: it keeps receiving there

Code Examples

curl -X DELETE "$BASE/api/v1/projects/$PID/instagram/accounts/$ACCOUNT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → 200 { "id": "…", "is_active": false, "needs_reconnect": true, "unsubscribed": true, … }

Details

Errors

  • 410 account_already_disconnected — it was disconnected before — also the answer to a second DELETE sent at the same time.
  • 404 account_not_found — not an account of this project.
GET/api/v1/projects/{projectId}/instagram/conversations#

Who wrote in

One row per person who has written to one of the project’s accounts, most recent message first — in both modes, so a conversation the assistant is having is readable too. Each row says where it stands against the messaging windows and whether the assistant is paused there. This is also the list of people you may write to.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "participant_id": "string",
  "since": "ISO datetime",
  "assistant": "\"paused\" | \"active\"",
  "limit": "integer",
  "offset": "integer"
}
Fields6Expand
account_id
uuidoptional
query — one account only; 404 if it is not on this project
participant_id
stringoptional
query — one person: the person’s Instagram-scoped id (IGSID)
since
ISO datetimeoptional
query — conversations with a message from the person at or after this moment
assistant
"paused" | "active"optional
query — conversations where a person took over, or not
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].account_id": "uuid",
  "data[].channel": "\"instagram\"",
  "data[].participant_id": "string",
  "data[].name": "string | null",
  "data[].username": "string | null",
  "data[].first_inbound_at": "ISO timestamp | null",
  "data[].last_inbound_at": "ISO timestamp | null",
  "data[].last_outbound_at": "ISO timestamp | null",
  "data[].inbound_count": "integer",
  "data[].outbound_count": "integer",
  "data[].last_message": "{ direction: \"inbound\" | \"outbound\", preview: string } | null",
  "data[].window": "{ state: \"standard\" | \"human_agent\" | \"closed\", standard_until: ISO | null, human_agent_until: ISO | null }",
  "data[].assistant": "{ state: \"active\" | \"paused\", paused_until: ISO | null }",
  "data[].created_at": "ISO timestamp",
  "data[].updated_at": "ISO timestamp",
  "page": "{ limit, offset, has_more }"
}
Fields17Expand
data[].id
uuid
usable as conversation_id when reading or sending
data[].account_id
uuid
data[].channel
"instagram"
data[].participant_id
string
the person’s Instagram-scoped id (IGSID); use it as `to` when replying
data[].name
string | null
the person’s name, as Meta shares it
data[].username
string | null
the person’s @username
data[].first_inbound_at
ISO timestamp | null
data[].last_inbound_at
ISO timestamp | null
every window runs from here
data[].last_outbound_at
ISO timestamp | null
data[].inbound_count
integer
data[].outbound_count
integer
messages that left (failed sends not counted)
data[].last_message
{ direction: "inbound" | "outbound", preview: string } | null
data[].window
{ state: "standard" | "human_agent" | "closed", standard_until: ISO | null, human_agent_until: ISO | null }
what may be sent right now
data[].assistant
{ state: "active" | "paused", paused_until: ISO | null }
paused while a person handles the conversation
data[].created_at
ISO timestamp
data[].updated_at
ISO timestamp
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/conversations?account_id=$ACCOUNT_ID&since=$(date -u +%Y-%m-%dT00:00:00Z)" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/instagram/conversations/{conversationId}#

Read a conversation

One conversation, same fields as a row of the listing — read it before a person replies to see which window is open.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the same object as one row of the listing"
}
Fields1Expand
…
the same object as one row of the listing

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/conversations/$CONVERSATION_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

Errors

  • 404 conversation_not_found — not a conversation of this project and channel.
PUT/api/v1/projects/{projectId}/instagram/conversations/{conversationId}#

Pause or resume the assistant in one conversation

A person handling a conversation does not want the assistant talking over them. "paused" keeps the assistant silent in this conversation only (for 24 hours, or paused_hours); "active" lets it answer again right away. It is paused for you when a person replies — from the console, through this API with human_agent, or in Meta’s own inbox. Meaningful for assistant-mode accounts.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "assistant": "\"paused\" | \"active\"",
  "paused_hours": "integer"
}
Fields2Expand
assistant
"paused" | "active"required
paused_hours
integeroptional
1..720 — how long a pause lasts; default 24

Response Schema

JSON type shapeExpand
{
  "…": "the conversation, with assistant.state and assistant.paused_until updated"
}
Fields1Expand
…
the conversation, with assistant.state and assistant.paused_until updated

Code Examples

curl -X PUT "$BASE/api/v1/projects/$PID/instagram/conversations/$CONVERSATION_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "assistant": "active" }'

Details

Errors

  • 400 — assistant missing or not one of the two values, paused_hours out of range.
  • 404 conversation_not_found — not a conversation of this project and channel.
GET/api/v1/projects/{projectId}/instagram/messages#

Read messages

Every message on the project’s Instagram accounts, in both directions and both modes, newest first: what people sent, what the assistant answered, what you and your team sent, and what failed to send. Every incoming message is stored BEFORE any webhook delivery is attempted, so this is your catch-up when your endpoint was down — filter on since and order=asc.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "conversation_id": "uuid",
  "participant_id": "string",
  "direction": "\"inbound\" | \"outbound\"",
  "type": "text | image | video | audio | file | sticker | share | story_mention | story_reply | reaction | postback | referral | unsupported | unknown | unsent | deleted",
  "status": "received | sent | delivered | read | failed",
  "author": "customer | assistant | api | person | page_inbox | workflow",
  "since": "ISO datetime",
  "until": "ISO datetime",
  "order": "\"desc\" (default) | \"asc\"",
  "include_payload": "true",
  "limit": "integer",
  "offset": "integer"
}
Fields13Expand
account_id
uuidoptional
query
conversation_id
uuidoptional
query
participant_id
stringoptional
query — messages from or to this person
direction
"inbound" | "outbound"optional
query
type
text | image | video | audio | file | sticker | share | story_mention | story_reply | reaction | postback | referral | unsupported | unknown | unsent | deletedoptional
query
status
received | sent | delivered | read | failedoptional
query
author
customer | assistant | api | person | page_inbox | workflowoptional
query
since
ISO datetimeoptional
query — on the moment the message happened on Instagram
until
ISO datetimeoptional
query
order
"desc" (default) | "asc"
include_payload
trueoptional
query — include each event exactly as Instagram delivered it (inbound) or the request as it was sent (outbound)
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].account_id": "uuid",
  "data[].conversation_id": "uuid",
  "data[].channel": "\"instagram\"",
  "data[].direction": "\"inbound\" | \"outbound\"",
  "data[].message_id": "string | null",
  "data[].author": "\"customer\" | \"assistant\" | \"api\" | \"person\" | \"page_inbox\" | \"workflow\"",
  "data[].from": "string",
  "data[].to": "string",
  "data[].type": "text | image | video | audio | file | sticker | share | story_mention | story_reply | reaction | postback | referral | unsupported | unknown | unsent | deleted",
  "data[].text": "string | null",
  "data[].attachments": "[{ id, type, url, mime_type, name }]",
  "data[].tag": "\"HUMAN_AGENT\" | null",
  "data[].reply_to": "string | null",
  "data[].status": "\"received\" for inbound; \"sent\" → \"delivered\" → \"read\", or \"failed\", for outbound",
  "data[].error": "{ code, message } | null",
  "data[].sent_at": "ISO timestamp",
  "data[].delivered_at": "ISO timestamp | null",
  "data[].read_at": "ISO timestamp | null",
  "data[].webhook": "{ status: \"none\" | \"pending\" | \"delivered\" | \"partial\" | \"failed\", delivered_at } for an inbound message of an API-mode account (\"partial\": some of your hooks accepted it, not all); null otherwise",
  "data[].api_key_id": "uuid | null",
  "data[].created_at": "ISO timestamp",
  "data[].payload": "object | null",
  "page": "{ limit, offset, has_more }"
}
Fields24Expand
data[].id
uuid
data[].account_id
uuid
data[].conversation_id
uuid
data[].channel
"instagram"
data[].direction
"inbound" | "outbound"
data[].message_id
string | null
Instagram’s own id of the message; pass it as reply_to to quote it
data[].author
"customer" | "assistant" | "api" | "person" | "page_inbox" | "workflow"
who wrote it: the person, the project’s assistant, your application, a person from the console, a person in Meta’s own inbox, or a workflow
data[].from
string
the sender’s id (the person’s, or the account’s external_id)
data[].to
string
the recipient’s id
data[].type
text | image | video | audio | file | sticker | share | story_mention | story_reply | reaction | postback | referral | unsupported | unknown | unsent | deleted
"unsent": the person took the message back on Instagram; "deleted": a person of the business removed it from Ainvented in the inbox (it stays on Instagram). Either way the message keeps its ids and times and no longer has its content
data[].text
string | null
the text; a pressed button’s title (postback); the emoji of a reaction; null once the message is "unsent" or "deleted"
data[].attachments
[{ id, type, url, mime_type, name }]
the files; id is what GET /media/{mediaId} takes, url is Meta’s own (it expires); empty once the message is "unsent" or "deleted"
data[].tag
"HUMAN_AGENT" | null
set on a reply a person sent after the 24-hour window
data[].reply_to
string | null
the message_id this one answers
data[].status
"received" for inbound; "sent" → "delivered" → "read", or "failed", for outbound
data[].error
{ code, message } | null
why an outbound message failed (`code` in the platform’s words, e.g. outside_messaging_window, meta_outcome_unknown; Meta’s own number is `meta_code` in the payload). On an incoming message of an assistant account: why the assistant did not answer it — assistant_usage_limit (the project reached its spending or token limit), assistant_failed (it could not answer, twice), assistant_outcome_unknown (its answer may not have reached the person and was not sent again)
data[].sent_at
ISO timestamp
when it happened on Instagram
data[].delivered_at
ISO timestamp | null
data[].read_at
ISO timestamp | null
data[].webhook
{ status: "none" | "pending" | "delivered" | "partial" | "failed", delivered_at } for an inbound message of an API-mode account ("partial": some of your hooks accepted it, not all); null otherwise
data[].api_key_id
uuid | null
the key that sent an outbound message
data[].created_at
ISO timestamp
data[].payload
object | null
only with include_payload=true (and on one message, and in every webhook event): the event exactly as Instagram delivered it, or the request as it was sent; null once the message is "unsent" or "deleted"
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/messages?direction=inbound&since=2026-11-10T08:00:00Z&order=asc&limit=200" \
  -H "Authorization: Bearer $ADMIN_KEY"
POST/api/v1/projects/{projectId}/instagram/messages#

Send a message

Sends a message from one of the project’s accounts to a person who has written to it — Instagram only lets a business answer people who wrote first. Within 24 hours of the person’s last message anything may be sent. From 24 hours to 7 days only a reply typed by a PERSON may go, and only marked with "human_agent": true (it travels with Meta’s HUMAN_AGENT tag — never use it for automated messages). After 7 days nothing can be sent until the person writes again. A long text is cut into several messages (1,000 bytes of UTF-8 each); a file goes as its own message after the text. Every attempt that reached Instagram is stored — a refused send is a message with status "failed" and its reason; a request refused before that (an invalid body, a closed window, an account that needs reconnecting) changes nothing and is not stored. Nothing is generated on your behalf. Retries: send an Idempotency-Key header (8-128 characters: letters, digits, _ . : -) and a retry of the same request — after a timeout or a lost answer — returns the first answer again, with the header Idempotent-Replayed: true, instead of sending a second message. Keys are kept 24 hours per project. The same key with a different body is refused (422); a retry while the first is still running gets 409. A refusal that sent nothing frees the key, so the corrected request can reuse it. When Instagram does not confirm a send in time, the answer is 504 meta_outcome_unknown: the message may have been delivered — do not resend it blindly (the conversation shows it as sent once Instagram’s echo arrives).

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account. Also subject to the key’s rate limit (429 rate_limit_exceeded with Retry-After).

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "to": "string",
  "conversation_id": "uuid",
  "Idempotency-Key": "header",
  "type": "\"text\" | \"image\" | \"video\" | \"audio\" | \"file\"",
  "text": "string (max 20,000)",
  "media_url": "https url",
  "reply_to": "string",
  "human_agent": "boolean"
}
Fields9Expand
account_id
uuidrequired
the account to send from; must be active
to
string
the person’s Instagram-scoped id (IGSID). Either to or conversation_id is required
conversation_id
uuid
the conversation to answer, instead of to
Idempotency-Key
headeroptional
recommended — 8-128 characters: letters, digits, _ . : -. A retry with the same key and body returns the first answer (Idempotent-Replayed: true) and sends nothing again
type
"text" | "image" | "video" | "audio" | "file"optional
"text" when there is no media_url; with a media_url and no type, the kind comes from the URL’s extension (.jpg .png .gif .webp → image, .mp4 .mov → video, .mp3 .m4a .ogg → audio, anything else → file)
text
string (max 20,000)
the text; past 1,000 bytes of UTF-8 it is sent as several messages. Required for type "text"; sent before the file for the other types
media_url
https url
where Meta fetches the file from; required for the file types (its kind is read from the extension when type is left out)
reply_to
stringoptional
the message_id of the message being answered; renders as a quoted reply
human_agent
booleanoptional
true ONLY for a reply typed by a person: allows it up to 7 days after the person’s last message, and lets a person step into an account the assistant answers (the assistant then pauses in that conversation)

Response Schema

JSON type shapeExpand
{
  "…": "the first stored message, same shape as a row of GET /messages, status \"sent\", HTTP 201",
  "additional_messages": "array"
}
Fields2Expand
…
the first stored message, same shape as a row of GET /messages, status "sent", HTTP 201
additional_messages
array
the other messages, when the text was cut into several or a file followed it

Code Examples

The Idempotency-Key makes a retry harmless: send the same request again with the same key and you get the first answer back, never a second message.

curl -X POST "$BASE/api/v1/projects/$PID/instagram/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Idempotency-Key: order-4521-shipped" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "to": "1780012345678901",
    "text": "Your order 4521 ships tomorrow. Anything else we can help with?",
    "reply_to": "aWdfZAG1faW…"
  }'
# → 201 { "id": "…", "direction": "outbound", "author": "api", "status": "sent", "message_id": "…", "additional_messages": [] }
# The same request again → the same 201, with "Idempotent-Replayed: true" — nothing is sent twice

Only for a reply your agent typed. It is sent with Meta’s HUMAN_AGENT tag and stored with tag "HUMAN_AGENT".

curl -X POST "$BASE/api/v1/projects/$PID/instagram/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "conversation_id": "'$CONVERSATION_ID'",
    "text": "Hi Ana, I checked with the warehouse: your parcel left this morning.",
    "human_agent": true
  }'
curl -X POST "$BASE/api/v1/projects/$PID/instagram/messages" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "'$ACCOUNT_ID'",
    "to": "1780012345678901",
    "type": "file",
    "media_url": "https://acme.example/invoices/4521.pdf",
    "text": "Here is your invoice."
  }'
{
  "error": {
    "message": "More than 24 hours have passed since this person's last Instagram message. Only a reply typed by a person can be sent now (up to 7 days): send it with \"human_agent\": true.",
    "type": "invalid_request_error",
    "code": "human_agent_required",
    "details": { "meta_code": null, "meta_message": null, "retryable": false, "message_id": null, "sent_message_ids": [] }
  }
}

Details

Errors

  • 400 — the offending field is named in error.param: neither to nor conversation_id, a text message without text, a file type without an https media_url.
  • 400 invalid_idempotency_key — the Idempotency-Key header is not 8-128 characters of letters, digits, _ . : -
  • 404 conversation_not_found — this person never wrote to this account — Meta lets a business answer only people who wrote first.
  • 404 account_not_found — not an account of this project.
  • 409 account_not_api_mode — the assistant answers this account. Switch it to API mode, or send a reply typed by a person with human_agent: true.
  • 409 account_inactive — the account is switched off.
  • 409 account_reauthorization_required — the customer’s authorization is no longer valid. Mint a new connect link; the account keeps its id and history.
  • 409 human_agent_required — more than 24 hours have passed: only a reply typed by a person, marked human_agent: true, may go now (up to 7 days).
  • 409 outside_messaging_window — more than 7 days have passed since the person’s last message (or Meta refused the window). Nothing can be sent until they write again.
  • 409 recipient_unavailable — the person cannot receive messages from the account right now (they blocked it, or their profile is gone).
  • 429 meta_rate_limited — Instagram is limiting how fast this account sends; details.retryable is true — retry in a moment.
  • 502 meta_permission_error — the customer did not grant the permission the message needs; have them reconnect and accept every permission.
  • 502 meta_send_failed — Instagram refused the message, or could not be reached and nothing was sent; details.meta_code and details.meta_message say why, details.retryable whether waiting helps, details.message_id is the failed row. When a long text failed part-way, details.sent_message_ids are the parts that did go.
  • 504 meta_outcome_unknown — Instagram did not confirm the message in time: it may have been delivered. Do not resend it blindly — check the conversation (it turns "sent" when Instagram’s echo arrives); a retry with the same Idempotency-Key returns this same answer.
  • 409 idempotency_key_in_use — a request with this Idempotency-Key is still running; retry in a moment.
  • 422 idempotency_key_reused — this Idempotency-Key was used with a different request; use a new key for a new message.
  • 500 outcome_unknown — an error after the message was handed to Meta: it may have been sent — check the conversation before sending it again.
  • 429 rate_limit_exceeded — your key’s bucket is empty; honour Retry-After.
GET/api/v1/projects/{projectId}/instagram/messages/{messageId}#

Read a message

One message with its full payload — the event exactly as Instagram delivered it, or the request as it was sent.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the same object as a row of GET /messages, payload included"
}
Fields1Expand
…
the same object as a row of GET /messages, payload included

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/messages/$MESSAGE_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

Errors

  • 404 message_not_found — not a message of this project and channel.
GET/api/v1/projects/{projectId}/instagram/media/{mediaId}#

Download a file a person sent

The bytes of a picture, video, voice note or document a person sent, streamed with its content type. mediaId is the attachments[].id of an incoming message. Instagram keeps the file only for a while: download what you need to keep.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "body": "the file bytes",
  "Content-Type": "the file’s type, e.g. image/jpeg, audio/mp4, application/pdf",
  "Content-Disposition": "inline, with the file name when Meta gave one"
}
Fields3Expand
body
the file bytes
Content-Type
the file’s type, e.g. image/jpeg, audio/mp4, application/pdf
Content-Disposition
inline, with the file name when Meta gave one

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/media/$MEDIA_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" -o photo.jpg

Details

Errors

  • 400 — not a media id (it looks like <message id>.<n>).
  • 404 media_not_found — unknown id, a message you sent (only files people sent are served), an attachment without a file, or a message that was unsent or deleted since (its files went with it).
  • 410 media_unavailable — Instagram no longer serves the file (its link expired), or it is larger than the limit (25 MB).
GET/api/v1/projects/{projectId}/instagram/comments#

Read comments

Every comment written on the posts of the project’s Instagram professional accounts, newest first, in both modes: who wrote it, on which media, and how it was answered — publicly, privately, by whom. The account’s own comments (its answers included) are never listed.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "post_id": "string",
  "status": "\"received\" | \"replied\" | \"failed\"",
  "since": "ISO datetime",
  "until": "ISO datetime",
  "order": "\"desc\" (default) | \"asc\"",
  "include_payload": "true",
  "limit": "integer",
  "offset": "integer"
}
Fields9Expand
account_id
uuidoptional
query
post_id
stringoptional
query — the comments of one media
status
"received" | "replied" | "failed"optional
query
since
ISO datetimeoptional
query — on the moment the comment was written
until
ISO datetimeoptional
query
order
"desc" (default) | "asc"
include_payload
trueoptional
query — include each change exactly as Meta delivered it
limit
integeroptional
query, 1..200, default 20
offset
integeroptional
query, default 0

Response Schema

JSON type shapeExpand
{
  "data[].id": "uuid",
  "data[].account_id": "uuid",
  "data[].channel": "\"instagram\"",
  "data[].comment_id": "string",
  "data[].post_id": "string | null",
  "data[].parent_id": "string | null",
  "data[].author": "{ id, name: null, username }",
  "data[].text": "string | null",
  "data[].media_type": "string | null",
  "data[].permalink": "string | null",
  "data[].status": "\"received\" | \"replied\" | \"failed\"",
  "data[].public_reply": "{ id, text, at } | null",
  "data[].private_reply": "{ message_id, text, at } | null",
  "data[].replied_by": "\"assistant\" | \"api\" | \"person\" | null",
  "data[].can_private_reply": "boolean",
  "data[].private_reply_until": "ISO timestamp",
  "data[].error": "{ code, message } | null",
  "data[].commented_at": "ISO timestamp",
  "data[].webhook": "{ status: \"none\" | \"pending\" | \"delivered\" | \"partial\" | \"failed\", delivered_at } | null",
  "data[].created_at": "ISO timestamp",
  "data[].updated_at": "ISO timestamp",
  "data[].payload": "object",
  "page": "{ limit, offset, has_more }"
}
Fields23Expand
data[].id
uuid
the comment id the replies endpoint takes
data[].account_id
uuid
data[].channel
"instagram"
data[].comment_id
string
Instagram’s own id of the comment
data[].post_id
string | null
the media it was written under
data[].parent_id
string | null
set when it answers another comment
data[].author
{ id, name: null, username }
data[].text
string | null
data[].media_type
string | null
FEED, REELS, STORY, AD… or LIVE for a live video
data[].permalink
string | null
a link to the post, once known
data[].status
"received" | "replied" | "failed"
data[].public_reply
{ id, text, at } | null
the answer posted under the comment
data[].private_reply
{ message_id, text, at } | null
the private message sent to the person
data[].replied_by
"assistant" | "api" | "person" | null
data[].can_private_reply
boolean
false once the private reply went out or 7 days have passed
data[].private_reply_until
ISO timestamp
the comment’s time + 7 days
data[].error
{ code, message } | null
why the last reply failed; for the assistant: assistant_usage_limit, assistant_placeholder (its answer had a blank to fill in, like [price] — it is never posted; add that information to its instructions), assistant_failed or assistant_outcome_unknown
data[].commented_at
ISO timestamp
data[].webhook
{ status: "none" | "pending" | "delivered" | "partial" | "failed", delivered_at } | null
the delivery of the comment event (API mode)
data[].created_at
ISO timestamp
data[].updated_at
ISO timestamp
data[].payload
object
only with include_payload=true (and on one comment): the change exactly as Meta delivered it
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/comments?status=received&order=asc" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/instagram/comments/{commentId}#

Read a comment

One comment with its full payload and how it was answered.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the same object as a row of GET /comments, payload included"
}
Fields1Expand
…
the same object as a row of GET /comments, payload included

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/comments/$COMMENT_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

Errors

  • 404 comment_not_found — not a comment of this project and channel.
POST/api/v1/projects/{projectId}/instagram/comments/{commentId}/replies#

Reply to a comment

Answers a comment publicly (under it, as the Instagram professional account), privately (a message to the person who wrote it), or both in one call. A private reply can go ONCE per comment and within 7 days of it — Meta’s rule; when the person answers it, the conversation goes on like any other. Instagram answers top-level comments: a public reply to a reply lands under the top-level comment. Works in both modes. Nothing is generated: you decide the words. A text longer than Instagram takes is refused with its limit (400 text_too_long), never cut. Send an Idempotency-Key header and a retry of the same reply returns the first answer (Idempotent-Replayed: true) — the comment never gets the same answer twice.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account. Also subject to the key’s rate limit.

Request Schema

JSON type shapeExpand
{
  "Idempotency-Key": "header",
  "public_text": "string",
  "private_text": "string (optional, up to 1,000 bytes of UTF-8",
  "(either)": "at least one of the two is required"
}
Fields4Expand
Idempotency-Key
headeroptional
recommended — as for sending a message: a retry with the same key and body returns the first answer and posts nothing again
public_text
stringoptional
up to 2,200 characters — posted under the comment
private_text
string (optional, up to 1,000 bytes of UTF-8
one message) — sent to the person privately
(either)
at least one of the two is required

Response Schema

JSON type shapeExpand
{
  "…": "the comment, with public_reply / private_reply filled in, HTTP 201",
  "errors": "[{ which: \"public\" | \"private\", code, message }]"
}
Fields2Expand
…
the comment, with public_reply / private_reply filled in, HTTP 201
errors
[{ which: "public" | "private", code, message }]
the half that failed when the other succeeded

Code Examples

curl -X POST "$BASE/api/v1/projects/$PID/instagram/comments/$COMMENT_ID/replies" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "public_text": "Thanks! We just sent you the details by message.",
    "private_text": "Hi! The blue one is back in stock in sizes S to L. Want me to hold one for you?"
  }'
# → 201 { "id": "…", "status": "replied", "replied_by": "api",
#         "public_reply": { "id": "…", "text": "Thanks! …", "at": "…" },
#         "private_reply": { "message_id": "…", "text": "Hi! …", "at": "…" },
#         "can_private_reply": false, "errors": [] }

Details

Errors

  • 400 — neither public_text nor private_text.
  • 400 text_too_long — a text over its limit — public_text up to 2,200 characters, private_text one message (1,000 bytes of UTF-8); error.param names it.
  • 400 invalid_idempotency_key — the Idempotency-Key header is malformed.
  • 409 private_reply_in_progress — another request is sending this comment’s private reply right now (Meta allows one); look at the comment in a moment.
  • 409 idempotency_key_in_use — a request with this Idempotency-Key is still running.
  • 422 idempotency_key_reused — this Idempotency-Key was used with a different reply.
  • 504 meta_outcome_unknown — Instagram did not confirm the reply in time: it may have been posted — check the comment before replying again.
  • 500 outcome_unknown — an error after the reply was handed to Meta: it may have been posted.
  • 404 comment_not_found — not a comment of this project and channel.
  • 409 account_inactive — the account is switched off.
  • 409 account_reauthorization_required — the authorization is no longer valid; have the customer reconnect.
  • 409 private_reply_already_sent — the comment already has its private reply (Meta allows one).
  • 409 private_reply_window_closed — more than 7 days have passed since the comment.
  • 409 recipient_unavailable — the person can no longer receive a private message from the account.
  • 429 meta_rate_limited — Instagram is limiting how fast the account replies; retry in a moment.
  • 429 rate_limit_exceeded — your key’s bucket is empty; honour Retry-After.
  • 502 meta_reply_failed — Instagram refused the reply (meta_permission_error when a permission is missing). details.errors lists each half with its code, its message and Instagram’s own number in meta_code.
POST/api/v1/projects/{projectId}/instagram/webhooks#

Register a webhook

Where the messages, comments and statuses of the project’s API-mode Instagram accounts are delivered. A hook may listen to every account of the project or to one. It is a project webhook — same signature, retries and auto-disable rules as the budget hooks — and its secret is returned once, here. Idempotent: registering the same url on the same scope again, when the hook already listens to every event asked, answers that hook — 200, reused: true, no secret — instead of a second one.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "url": "https url",
  "account_id": "uuid | null",
  "events": "[\"instagram.message.received\", \"instagram.message.status\", \"instagram.message.echo\", \"instagram.message.deleted\", \"instagram.comment.received\"]"
}
Fields3Expand
url
https urlrequired
public host; private and loopback addresses are refused
account_id
uuid | nulloptional
deliver only this account’s events; omit or null for every account of the project
events
["instagram.message.received", "instagram.message.status", "instagram.message.echo", "instagram.message.deleted", "instagram.comment.received"]optional
default ["instagram.message.received", "instagram.comment.received"]

Response Schema

JSON type shapeExpand
{
  "id": "uuid",
  "url": "string",
  "account_id": "uuid | null",
  "events": "string[]",
  "is_active": "boolean",
  "secret": "hex string",
  "reused": "boolean",
  "created_at": "ISO timestamp",
  "updated_at": "ISO timestamp",
  "last_delivery_at": "ISO timestamp | null",
  "failure_count": "integer"
}
Fields11Expand
id
uuid
url
string
account_id
uuid | null
events
string[]
is_active
boolean
secret
hex string
shown ONCE, on a 201 only; check every delivery’s signature with it
reused
boolean
true: the existing hook was answered (200, no secret); false: created (201)
created_at
ISO timestamp
updated_at
ISO timestamp
last_delivery_at
ISO timestamp | null
failure_count
integer
consecutive failed deliveries; the hook is disabled at 20

Code Examples

curl -X POST "$BASE/api/v1/projects/$PID/instagram/webhooks" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://acme.example/instagram/inbound",
    "account_id": "'$ACCOUNT_ID'",
    "events": ["instagram.message.received", "instagram.comment.received", "instagram.message.echo"]
  }'
# → 201 { "id": "…", "secret": "0f3a…", … }   ← store the secret now

Details

Errors

  • 400 — an unknown event (another channel’s too), or a url that is not public https.
  • 404 account_not_found — account_id is not an account of this project.
GET/api/v1/projects/{projectId}/instagram/webhooks#

List webhooks

The project’s Instagram webhooks, without secrets. Budget hooks and other channels’ hooks of the same project are not shown here.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "account_id": "uuid",
  "include_disabled": "true"
}
Fields2Expand
account_id
uuidoptional
query — the hooks that would fire for this account: its own and the project-wide ones
include_disabled
trueoptional
query

Response Schema

JSON type shapeExpand
{
  "data[]": "the webhook objects, without secrets"
}
Fields1Expand
data[]
the webhook objects, without secrets

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/webhooks" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/projects/{projectId}/instagram/webhooks/{webhookId}#

Read a webhook

One Instagram webhook, without its secret. A hook of another channel, or a budget hook, is 404 here.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "…": "the webhook object, without its secret"
}
Fields1Expand
…
the webhook object, without its secret

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"

Details

Errors

  • 404 webhook_not_found — not a webhook of this channel on this project; an id that is not a UUID is answered the same way.
PUT/api/v1/projects/{projectId}/instagram/webhooks/{webhookId}#

Update a webhook

Change the url, the events, the account it listens to, switch it on or off, or rotate its secret (the new one is returned once, and the failure count starts again). Switching it back on — also after the auto-disable — restarts its failure count. Every change is written to the project’s audit log.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "url": "https url",
  "account_id": "uuid | null",
  "events": "string[]",
  "is_active": "boolean",
  "rotate_secret": "true"
}
Fields5Expand
url
https urloptional
account_id
uuid | nulloptional
null makes it project-wide
events
string[]optional
this channel’s events only
is_active
booleanoptional
rotate_secret
trueoptional
mint a new secret

Response Schema

JSON type shapeExpand
{
  "…": "the webhook object; secret only when rotated"
}
Fields1Expand
…
the webhook object; secret only when rotated

Code Examples

curl -X PUT "$BASE/api/v1/projects/$PID/instagram/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "rotate_secret": true }'
# → 200 { …, "secret": "new hex" }

Details

Errors

  • 400 — an empty patch or a body with none of the fields, an unknown event, a url that is not public https.
  • 404 webhook_not_found — not a webhook of this channel on this project; an id that is not a UUID is answered the same way.
DELETE/api/v1/projects/{projectId}/instagram/webhooks/{webhookId}#

Deactivate a webhook

Stops deliveries to it. The hook and its delivery log are kept; a PUT with is_active true switches it back on.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Code Examples

curl -X DELETE "$BASE/api/v1/projects/$PID/instagram/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → 204

Details

Errors

  • 410 — it was already inactive.
  • 404 webhook_not_found — not a webhook of this channel on this project; an id that is not a UUID is answered the same way.
POST/api/v1/projects/{projectId}/instagram/webhooks/{webhookId}/test#

Test a webhook

Sends a sample instagram.message.received event, signed like a real one, with data.test = true and a real account of the project — one attempt with the same 8-second timeout as a real delivery, so the answer says what your endpoint did right now. A failing test never counts toward the auto-disable.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Response Schema

JSON type shapeExpand
{
  "delivered": "boolean",
  "attempts": "integer",
  "event_id": "uuid",
  "response_status": "integer | null",
  "error": "string | null"
}
Fields5Expand
delivered
boolean
your endpoint answered 2xx
attempts
integer
1
event_id
uuid
the id of the sample event
response_status
integer | null
the HTTP status your endpoint answered
error
string | null
http_<status> | timeout | fetch_error | url_<reason>

Code Examples

curl -X POST "$BASE/api/v1/projects/$PID/instagram/webhooks/$WEBHOOK_ID/test" \
  -H "Authorization: Bearer $ADMIN_KEY"
# → 202 { "delivered": true, "attempts": 1, "event_id": "…" }

Details

Errors

  • 404 webhook_not_found — not an active webhook of this channel on this project; an id that is not a UUID is answered the same way.
GET/api/v1/projects/{projectId}/instagram/traffic#

Traffic of a project

Messages and comments per day on one project — received, sent, failed — zero-filled over the window, plus how many people wrote and how many accounts are active. A handful of grouped queries whatever the volume; the Partner Console draws its chart from it.

Authentication

Bearer <admin_api_key> — Admin key, project owner, reseller account.

Request Schema

JSON type shapeExpand
{
  "from": "string",
  "to": "string",
  "group_by": "\"day\" (default) | \"account\"",
  "account_id": "uuid"
}
Fields4Expand
from
stringoptional
ISO datetime or YYYY-MM-DD. Defaults to 30 days before to.
to
stringoptional
ISO datetime or YYYY-MM-DD (a bare date covers its whole day). Defaults to now. The window may not exceed 90 days.
group_by
"day" (default) | "account"
"account" adds a per-account breakdown
account_id
uuidoptional
narrow the report to one account

Response Schema

JSON type shapeExpand
{
  "project_id": "uuid",
  "window": {
    "from": "ISO",
    "to": "ISO"
  },
  "channel": "\"instagram\"",
  "group_by": "string",
  "totals": {
    "inbound": "integer",
    "outbound": "integer",
    "total": "integer",
    "failed": "integer",
    "comments": "integer",
    "active_conversations": "integer",
    "accounts": "integer"
  },
  "series": [
    {
      "bucket": "YYYY-MM-DD (UTC)",
      "inbound": "integer",
      "outbound": "integer",
      "total": "integer",
      "failed": "integer",
      "comments": "integer"
    }
  ],
  "by_account": [
    {
      "account_id": "uuid",
      "project_id": "uuid",
      "name": "string | null",
      "display_name": "string | null",
      "username": "string | null",
      "inbound": "integer",
      "outbound": "integer",
      "total": "integer",
      "failed": "integer",
      "comments": "integer"
    }
  ]
}
Fields32Expand
project_id
uuid
window
object
object — fields below
from
ISO
to
ISO
channel
"instagram"
group_by
string
totals
object
object — fields below
inbound
integer
messages received
outbound
integer
messages sent (by the assistant, your application, people or workflows)
total
integer
failed
integer
sends that failed
comments
integer
comments received
active_conversations
integer
people who wrote in the window
accounts
integer
active accounts
series
array
array — fields below
bucket
YYYY-MM-DD (UTC)
inbound
integer
outbound
integer
total
integer
failed
integer
comments
integer
by_account
array
array — fields below
account_id
uuid
project_id
uuid
name
string | null
display_name
string | null
username
string | null
inbound
integer
outbound
integer
total
integer
failed
integer
comments
integer

Code Examples

curl "$BASE/api/v1/projects/$PID/instagram/traffic?from=2026-11-01&to=2026-11-30&group_by=account" \
  -H "Authorization: Bearer $ADMIN_KEY"
GET/api/v1/instagram/accounts#

Every account, all projects

Every Instagram professional account connected to any of your projects, in one paged list with its project. The account-wide counterpart of the per-project list — one call for a thousand projects, never one per project.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "mode": "\"api\" | \"assistant\"",
  "include_inactive": "true",
  "project_ids": "string",
  "limit": "integer",
  "offset": "integer"
}
Fields5Expand
mode
"api" | "assistant"optional
include_inactive
trueoptional
project_ids
stringoptional
comma-separated project UUIDs (at most 1000); ids you do not own simply do not match
limit
integeroptional
1..200, default 50
offset
integeroptional
default 0

Response Schema

JSON type shapeExpand
{
  "data[]": "the account object (without webhook_count), plus project_name",
  "page": "{ limit, offset, has_more }"
}
Fields2Expand
data[]
the account object (without webhook_count), plus project_name
page
{ limit, offset, has_more }

Code Examples

curl "$BASE/api/v1/instagram/accounts?mode=api&limit=100" \
  -H "Authorization: Bearer $ADMIN_KEY"
PUT/api/v1/instagram/accounts#

Bulk mode, active and comment replies

Set who answers, whether accounts are active, and what the assistant does with comments — on every Instagram account of your projects in one call, or on a selection by project and/or account. One transaction; one audit row (marked bulk) per account whose stored value actually changes; a re-apply writes nothing. Switching on reaches only accounts that still hold their authorization, and leaves untouched — listed in skipped — an account another connection already holds (one active connection per Instagram professional account), or a second copy of one in the selection.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "mode": "\"api\" | \"assistant\"",
  "is_active": "boolean",
  "comment_reply_mode": "\"off\" | \"public\" | \"private\" | \"both\"",
  "project_ids": "string[]",
  "account_ids": "string[]"
}
Fields5Expand
mode
"api" | "assistant"optional
at least one of mode / is_active / comment_reply_mode is required
is_active
booleanoptional
comment_reply_mode
"off" | "public" | "private" | "both"optional
project_ids
string[]optional
1..1000 project UUIDs; absent = every project of the account
account_ids
string[]optional
1..1000 account ids, narrowing the selection further

Response Schema

JSON type shapeExpand
{
  "matched": "integer",
  "updated": "integer",
  "mode": "echoed when sent",
  "is_active": "echoed when sent",
  "comment_reply_mode": "echoed when sent",
  "skipped": "[{ id, reason: \"account_in_use\" }]"
}
Fields6Expand
matched
integer
accounts in scope
updated
integer
accounts whose stored value changed
mode
echoed when sent
is_active
echoed when sent
comment_reply_mode
echoed when sent
skipped
[{ id, reason: "account_in_use" }]
always present; the accounts left untouched

Code Examples

curl -X PUT "$BASE/api/v1/instagram/accounts" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "assistant", "comment_reply_mode": "both", "project_ids": ["'"$PID"'"] }'
{ "matched": 3, "updated": 2, "mode": "assistant", "comment_reply_mode": "both", "skipped": [] }

Details

Errors

  • 409 account_in_use — an account in the selection was switched on concurrently by another connection; send the request again.
GET/api/v1/instagram/traffic#

Traffic, all projects

The same report as the per-project traffic, across every project you own (or a project_ids selection), with an optional per-project or per-account breakdown. Every figure comes from grouped queries — it costs the same for one project as for a thousand.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "from": "string",
  "to": "string",
  "group_by": "\"day\" (default) | \"project\" | \"account\"",
  "project_ids": "string",
  "account_id": "uuid"
}
Fields5Expand
from
stringoptional
ISO datetime or YYYY-MM-DD
to
stringoptional
at most 90 days after from
group_by
"day" (default) | "project" | "account"
project_ids
stringoptional
comma-separated project UUIDs (at most 1000)
account_id
uuidoptional
narrow the report to one account

Response Schema

JSON type shapeExpand
{
  "projects": "integer",
  "window": {
    "from": "ISO",
    "to": "ISO"
  },
  "channel": "\"instagram\"",
  "group_by": "string",
  "totals": "{ inbound, outbound, total, failed, comments, active_conversations, accounts }",
  "series": "[{ bucket, inbound, outbound, total, failed, comments }]",
  "by_project": "[{ project_id, name, inbound, outbound, total, failed, comments }]",
  "by_account": "[{ account_id, project_id, name, display_name, username, inbound, outbound, total, failed, comments }]"
}
Fields10Expand
projects
integer
projects in scope
window
object
object — fields below
from
ISO
to
ISO
channel
"instagram"
group_by
string
totals
{ inbound, outbound, total, failed, comments, active_conversations, accounts }
series
[{ bucket, inbound, outbound, total, failed, comments }]
by_project
[{ project_id, name, inbound, outbound, total, failed, comments }]
with group_by=project
by_account
[{ account_id, project_id, name, display_name, username, inbound, outbound, total, failed, comments }]
with group_by=account

Code Examples

curl "$BASE/api/v1/instagram/traffic?group_by=project" \
  -H "Authorization: Bearer $ADMIN_KEY"
POST/api/v1/instagram/webhooks#

Webhook on every project

Register one webhook URL on every project you own (or a project_ids selection) in a single call. One secret is minted for the whole batch and returned once, so an application that receives every customer’s events at one endpoint checks them all with one key. A project that already has an active project-wide hook on that URL listening to every event asked is left alone and reported as reused; a hook there listening to fewer events gets a new one beside it. Concurrent calls make one hook per project.

Authentication

Bearer Admin API key — reseller accounts only.

Request Schema

JSON type shapeExpand
{
  "url": "string",
  "events": "string[]",
  "project_ids": "string[]"
}
Fields3Expand
url
stringrequired
https URL; private, loopback and link-local addresses are refused
events
string[]optional
default ["instagram.message.received", "instagram.comment.received"]
project_ids
string[]optional
1..1000 project UUIDs; absent = every project of the account

Response Schema

JSON type shapeExpand
{
  "secret": "string | null",
  "created": "integer",
  "reused": "integer",
  "webhooks": "[{ id, project_id, url, events, is_active, reused, created_at }]"
}
Fields4Expand
secret
string | null
the one secret of every hook created, shown ONCE; null when nothing was created
created
integer
reused
integer
webhooks
[{ id, project_id, url, events, is_active, reused, created_at }]

Code Examples

curl -X POST "$BASE/api/v1/instagram/webhooks" \
  -H "Authorization: Bearer $ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://acme.example/instagram/inbound", "events": ["instagram.message.received", "instagram.comment.received"] }'
Guide

Webhook payload & signature

Every delivery is a JSON POST with the headers X-Ainvented-Event, X-Ainvented-Delivery (the event id) and X-Ainvented-Signature: sha256= followed by the hex HMAC-SHA256 of the raw body under your webhook's secret. Verify it before trusting a payload. Deliveries start right after Meta's own notification has been stored and acknowledged; answer with any 2xx within 8 seconds — anything else is retried once, and the message or comment is marked webhook.status = "failed" for you to read back ("partial" when some of your hooks accepted it and others did not). Deliveries are at-least-once: the same event delivered twice — a duplicate from Meta, or a delivery a restart cut, which is sent again within a few minutes — carries the same X-Ainvented-Delivery, so drop ids you have already processed.

  • instagram.message.received — data.message (with its payload), data.account, data.conversation.
  • instagram.message.status — data.status and the outbound data.message, already updated, for messages sent through the API or by a person from the console. Instagram reports read.
  • instagram.message.echo — a reply typed outside Ainvented (Meta's own inbox, the Instagram app, another tool), stored with author: "page_inbox"; data.message, data.account, data.conversation.
  • instagram.message.deleted — the person unsent a message. Its content is already gone from Ainvented: data.message is that message with type: "unsent", text: null, no attachments and a null payload (type: "deleted" when your team had already deleted it in the inbox), so match it by data.message.id or message_id and remove your own copy; with data.account and data.conversation. Not among a new webhook's default events: name it in events to receive it.
  • instagram.comment.received — data.comment (with its payload) and data.account.
instagram.message.received
{
  "id": "3f6c1a2e-…",
  "event": "instagram.message.received",
  "occurred_at": "2026-11-10T10:15:02.114Z",
  "project_id": "…",
  "data": {
    "message": {
      "id": "…",
      "account_id": "…",
      "conversation_id": "…",
      "channel": "instagram",
      "direction": "inbound",
      "message_id": "aWdfZAG1faW…",
      "author": "customer",
      "from": "1780012345678901",
      "to": "17841400123456789",
      "type": "image",
      "text": "is this the blue one?",
      "attachments": [
        {
          "id": "…message id….0",
          "type": "image",
          "url": "https://…",
          "mime_type": null,
          "name": null
        }
      ],
      "tag": null,
      "reply_to": null,
      "status": "received",
      "error": null,
      "sent_at": "2026-11-10T10:15:00.000Z",
      "delivered_at": null,
      "read_at": null,
      "webhook": {
        "status": "pending",
        "delivered_at": null
      },
      "api_key_id": null,
      "created_at": "2026-11-10T10:15:02.010Z",
      "payload": {
        "sender": {
          "id": "1780012345678901"
        },
        "recipient": {
          "id": "17841400123456789"
        },
        "timestamp": 1794305700000,
        "message": {
          "mid": "aWdfZAG1faW…",
          "text": "is this the blue one?",
          "attachments": [
            {
              "type": "image",
              "payload": {
                "url": "https://…"
              }
            }
          ]
        }
      }
    },
    "account": {
      "id": "…",
      "channel": "instagram",
      "name": "Acme Support",
      "external_id": "17841400123456789",
      "display_name": "Acme",
      "username": "acme.store"
    },
    "conversation": {
      "id": "…",
      "participant_id": "1780012345678901",
      "name": "Ana",
      "inbound_count": 3,
      "outbound_count": 2,
      "window": {
        "state": "standard",
        "standard_until": "2026-11-11T10:15:00.000Z",
        "human_agent_until": "2026-11-17T10:15:00.000Z"
      },
      "assistant": {
        "state": "active",
        "paused_until": null
      },
      "…": "…"
    }
  }
}
instagram.comment.received
{
  "id": "8a1d…",
  "event": "instagram.comment.received",
  "occurred_at": "2026-11-10T11:02:40.000Z",
  "project_id": "…",
  "data": {
    "comment": {
      "id": "…",
      "account_id": "…",
      "channel": "instagram",
      "comment_id": "17890123456789012",
      "post_id": "17912345678901234",
      "parent_id": null,
      "author": {
        "id": "1780012345678901",
        "name": null,
        "username": "ana.perez"
      },
      "text": "Do you ship to Bogotá?",
      "media_type": "FEED",
      "permalink": null,
      "status": "received",
      "public_reply": null,
      "private_reply": null,
      "replied_by": null,
      "can_private_reply": true,
      "private_reply_until": "2026-11-17T11:02:38.000Z",
      "error": null,
      "commented_at": "2026-11-10T11:02:38.000Z",
      "webhook": {
        "status": "pending",
        "delivered_at": null
      },
      "created_at": "2026-11-10T11:02:40.000Z",
      "updated_at": "2026-11-10T11:02:40.000Z",
      "payload": {
        "field": "comments",
        "value": {
          "…": "exactly as Meta delivered it"
        }
      }
    },
    "account": {
      "id": "…",
      "channel": "instagram",
      "name": "Acme Support",
      "external_id": "17841400123456789",
      "display_name": "Acme",
      "username": "acme.store"
    }
  }
}
Node — verify a delivery
# Node — verify a delivery
const crypto = require('crypto');
const expected = 'sha256=' + crypto.createHmac('sha256', WEBHOOK_SECRET).update(rawBody).digest('hex');
const ok = expected.length === signature.length &&
  crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature));
Guide

What your customer goes through

The page you send them is hosted by Ainvented and needs no account. They sign in with Instagram or with Facebook, in Meta’s own window, and choose the account to share — no Facebook Page is needed. If they share more than one, the page asks which one to connect. When they are done they land on your return_url, or on a success card.

Limits worth designing around

  • One account, one project. An account already active on another project is refused until it is disconnected there.
  • Reconnecting is the same call. The same account brought back to the same project is refreshed in place: same id, same history.
  • A professional account. Business or creator, and public for its comments to arrive. No Facebook Page is needed.
  • The authorization does not expire on a schedule. It stops only if the customer removes access in Meta's settings; the account then reads needs_reconnect: true and sends answer account_reauthorization_required.
  • Disconnecting keeps the history. DELETE /instagram/accounts/{accountId} stops the messages and forgets the authorization; conversations, messages and comments stay readable.
Reference · 3 endpoints

Project API keys

Each project may have multiple API keys, each scoped to that project. Keys are hashed with Argon2id; only the last 4 characters (partialKey) are stored for display. The full key is returned exactly once at creation.

In this section
  1. POSTCreate/api/v1/projects/{projectId}/api-keys
  2. GETList/api/v1/projects/{projectId}/api-keys
  3. DELETERevoke/api/v1/projects/{projectId}/api-keys/{keyId}
POST/api/v1/projects/{projectId}/api-keys#

Create an API key under a project

Creates a new ApiKey row scoped to the project. Returns the full key once.

Authentication

Bearer <api_key> — must own the project.

Request Schema

JSON type shapeExpand
{
  "label": "string"
}
Fields1Expand
label
stringrequired
1..100, trimmed

Response Schema

JSON type shapeExpand
{
  "id": "uuid",
  "key": "full key",
  "partialKey": "last 4 chars",
  "label": "string",
  "projectId": "uuid",
  "createdAt": "ISO"
}
Fields6Expand
id
uuid
key
full key
returned only once
partialKey
last 4 chars
label
string
projectId
uuid
createdAt
ISO

Code Examples

curl -X POST $BASE/api/v1/projects/$PID/api-keys \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "label": "prod-server-1" }'
GET/api/v1/projects/{projectId}/api-keys#

List API keys for a project

Returns active keys by default. Append ?include_revoked=true to also see revoked keys.

Authentication

Bearer <api_key> — must own the project.

Response Schema

JSON type shapeExpand
{
  "keys": [
    {
      "id": "uuid",
      "label": "string",
      "partialKey": "last 4 chars",
      "projectId": "uuid",
      "createdAt": "ISO",
      "lastUsedAt": "ISO | null",
      "revokedAt": "ISO | null",
      "requestCount": "number",
      "tokenUsage": "string (BigInt as string)"
    }
  ],
  "total": "number"
}
Fields11Expand
keys
array
array — fields below
id
uuid
label
string
partialKey
last 4 chars
projectId
uuid
createdAt
ISO
lastUsedAt
ISO | null
revokedAt
ISO | null
requestCount
number
tokenUsage
string (BigInt as string)
total
number

Code Examples

curl "$BASE/api/v1/projects/$PID/api-keys?include_revoked=true" -H "Authorization: Bearer $API_KEY"
DELETE/api/v1/projects/{projectId}/api-keys/{keyId}#

Revoke an API key

Sets revokedAt on the key. Subsequent calls using that key return 401. Already-revoked → 410. Cross-project mismatch → 404. Usage history is retained.

Authentication

Bearer <api_key> — must own the project.

Code Examples

curl -X DELETE $BASE/api/v1/projects/$PID/api-keys/$KEY_ID -H "Authorization: Bearer $API_KEY"
Reference · 1 endpoint

Consumption

Aggregates token + cost usage across your project. Each billable sub-call (completion, workflow, skill, assistant, connector) is recorded as its own usage event, so the reported totals always match what your project actually consumed.

In this section
  1. GETRead consumption/api/v1/projects/{projectId}/consumption
GET/api/v1/projects/{projectId}/consumption#

Read consumption breakdown

Returns a window of token + cost usage with a per-component breakdown and a time series. Window may not exceed 90 days. Defaults to the last 30 days UTC.

Authentication

Bearer <api_key> — must own the project.

Request Schema

JSON type shapeExpand
{
  "from": "ISO timestamp",
  "to": "ISO timestamp",
  "group_by": "\"day\" | \"component\" | \"model\"",
  "component_type": "\"completion\" | \"workflow\" | \"skill\" | \"assistant\" | \"connector\"",
  "model": "\"ainvented-eon\" | \"ainvented-epic\" | \"ainvented-saga\" | \"ainvented-lite\" | \"ainvented-low\" | \"(none)\""
}
Fields5Expand
from
ISO timestampoptional
default now-30d
to
ISO timestampoptional
default now
group_by
"day" | "component" | "model"optional
default "day"
component_type
"completion" | "workflow" | "skill" | "assistant" | "connector"optional
filters the whole response to one component
model
"ainvented-eon" | "ainvented-epic" | "ainvented-saga" | "ainvented-lite" | "ainvented-low" | "(none)"optional
; "ainvented-eon" where it is offered — filters the whole response to one model. In by_model the Lite tier keeps its earlier id, unchanged for compatibility

Response Schema

JSON type shapeExpand
{
  "project_id": "uuid",
  "currency": "string",
  "budget_cents": "number",
  "consumed_cents": "number",
  "remaining_cents": "number",
  "remaining_pct": "number",
  "budget_micros": "number",
  "consumed_micros": "number",
  "remaining_micros": "number",
  "exhausted": "boolean",
  "hard_cap": "boolean",
  "alert_thresholds": "number[]",
  "fired_thresholds": "number[]",
  "token_limit": "number",
  "consumed_tokens": "number",
  "remaining_tokens": "number",
  "remaining_tokens_pct": "number",
  "token_hard_cap": "boolean",
  "fired_token_thresholds": "number[]",
  "window": {
    "from": "ISO",
    "to": "ISO"
  },
  "totals": {
    "prompt_tokens": "number",
    "completion_tokens": "number",
    "total_tokens": "number",
    "cached_tokens": "number",
    "cost_cents": "number",
    "cost_micros": "number"
  },
  "by_component": {
    "completion": {
      "events": "number",
      "prompt_tokens": "number",
      "completion_tokens": "number",
      "cached_tokens": "number",
      "total_tokens": "number",
      "cost_cents": "number"
    },
    "workflow": "...same shape...",
    "skill": "...",
    "assistant": "...",
    "connector": "..."
  },
  "tokens_by_component": {
    "completion": "number",
    "workflow": "number",
    "skill": "number",
    "assistant": "number",
    "connector": "number"
  },
  "by_model": {
    "ainvented-epic": {
      "events": "number",
      "prompt_tokens": "number",
      "completion_tokens": "number",
      "cached_tokens": "number",
      "total_tokens": "number",
      "cost_cents": "number",
      "cost_micros": "number"
    },
    "ainvented-low": "...same shape...",
    "(none)": "...auxiliary calls with no billed model..."
  },
  "series": [
    {
      "bucket": "string",
      "prompt_tokens": "number",
      "completion_tokens": "number",
      "cached_tokens": "number",
      "total_tokens": "number",
      "cost_cents": "number",
      "cost_micros": "number"
    }
  ]
}
Fields66Expand
project_id
uuid
currency
string
budget_cents
number
consumed_cents
number
remaining_cents
number
remaining_pct
number
budget_micros
number
exact budget (10000 micros = 1 cent)
consumed_micros
number
EXACT consumption; consumed_cents is floor(consumed_micros/10000)
remaining_micros
number
exact remaining (clamped ≥ 0)
exhausted
boolean
true when the hard-cap budget is fully spent (the cap only: GET /balance's can_spend answers for every money gate)
hard_cap
boolean
alert_thresholds
number[]
fired_thresholds
number[]
token_limit
number
consumed_tokens
number
remaining_tokens
number
remaining_tokens_pct
number
token_hard_cap
boolean
fired_token_thresholds
number[]
window
object
object — fields below
from
ISO
to
ISO
totals
object
object — fields below
prompt_tokens
number
input tokens
completion_tokens
number
output tokens
total_tokens
number
cached_tokens
number
input tokens served from cache (a subset of prompt_tokens, billed at the discounted cached rate)
cost_cents
number
cost_micros
number
EXACT cost; cost_cents is floor(cost_micros/10000)
by_component
object
object — fields below
completion
object
object — fields below
events
number
prompt_tokens
number
input
completion_tokens
number
output
cached_tokens
number
cache-served input (subset of prompt_tokens)
total_tokens
number
cost_cents
number
workflow
...same shape...
skill
...
assistant
...
connector
...
tokens_by_component
object
object — fields below
completion
number
total tokens for completion events in the window
workflow
number
skill
number
assistant
number
connector
number
by_model
object
object — fields below
ainvented-epic
object
object — fields below
events
number
prompt_tokens
number
input tokens for this model
completion_tokens
number
output tokens for this model
cached_tokens
number
cache-served input for this model
total_tokens
number
cost_cents
number
cost_micros
number
exact cost for this model
ainvented-low
...same shape...
(none)
...auxiliary calls with no billed model...
series
array
array — fields below
bucket
string
prompt_tokens
number
input
completion_tokens
number
output
cached_tokens
number
cache-served input
total_tokens
number
cost_cents
number
cost_micros
number
exact cost for the bucket

Code Examples

Last 7 days, grouped by component, only workflow events.

FROM=$(node -p "new Date(Date.now() - 7*864e5).toISOString()")
curl "$BASE/api/v1/projects/$PID/consumption?from=$FROM&group_by=component&component_type=workflow" \
  -H "Authorization: Bearer $API_KEY"

Scope the whole report (totals, by_component, by_model, series) to a single model.

curl "$BASE/api/v1/projects/$PID/consumption?model=ainvented-low" \
  -H "Authorization: Bearer $API_KEY"
GET/api/v1/projects/{projectId}/balance#

Read a project's authoritative balance

Single source of truth for 'does this key/project have money?'. Money is reported at floored-cent precision (budget_cents/consumed_cents/remaining_cents, backward-compatible) AND exact micro precision (budget_micros/consumed_micros/remaining_micros; 10000 micros = 1 cent). `exhausted` is the cap: true when a hard cap is fully spent. `can_spend` answers whether the next billed call passes EVERY money gate — the cap, a hard token limit and your account balance wherever it pays: on a project without a budget from the first call, on a budgeted one once the money paid into it is used up (call by call, up to the cap). Poll `can_spend`: it never disagrees with the 402 a key receives. Not admin-gated: a project-scoped key may read its own balance.

Authentication

Bearer <api_key> — must own the project.

Response Schema

JSON type shapeExpand
{
  "project_id": "uuid",
  "budget_cents": "number",
  "consumed_cents": "number",
  "remaining_cents": "number",
  "budget_micros": "number",
  "consumed_micros": "number",
  "remaining_micros": "number",
  "exhausted": "boolean",
  "can_spend": "boolean",
  "remaining_pct": "number",
  "currency": "string",
  "hard_cap": "boolean",
  "token_limit": "number",
  "consumed_tokens": "number",
  "remaining_tokens": "number",
  "token_hard_cap": "boolean",
  "credited_cents": "number",
  "credited_remaining_cents": "number",
  "paid_from_balance_cents": "number",
  "draws_from_balance": "boolean"
}
Fields20Expand
project_id
uuid
budget_cents
number
consumed_cents
number
floor(consumed_micros/10000)
remaining_cents
number
budget_micros
number
consumed_micros
number
exact
remaining_micros
number
exhausted
boolean
true when consumed_micros >= budget_micros for a hard cap
can_spend
boolean
the next billed call passes every money gate: the cap, a hard token limit, and your account balance when it pays (a project without a budget, or beyond the money paid in)
remaining_pct
number
currency
string
hard_cap
boolean
token_limit
number
consumed_tokens
number
remaining_tokens
number
token_hard_cap
boolean
credited_cents
number
paid into the project, net of refunds and chargebacks (credited_micros: exact)
credited_remaining_cents
number
what the project can still spend before your account balance pays
paid_from_balance_cents
number
what your account balance has paid (paid_from_balance_micros: exact)
draws_from_balance
boolean
the next call is charged to your balance; it is refused when your balance is empty

Code Examples

Check whether a project-scoped key still has budget before relying on it.

curl "$BASE/api/v1/projects/$PID/balance" -H "Authorization: Bearer $API_KEY"
Reference · 3 endpoints

Promotions

Promo codes and referral share links. GET /api/promotions/resolve is fully public (it powers the /promo/<slug> landing pages) and returns a display-safe offer summary. Redeeming a code and reading your referral stats are browser-session endpoints: they authenticate with the session cookie of your signed-in ainvented account — not available with API keys. Money fields follow the platform conventions: offer credit amounts are USD dollars; caps, minimums and commission totals are integer cents.

In this section
  1. GETResolve a promo code/api/promotions/resolve
  2. POSTRedeem a promo code/api/billing/redeem-promo
  3. GETReferral stats/api/referrals/me
GET/api/promotions/resolve#

Resolve a promo code or share-link slug

Resolves a promo code or a share-link landing slug to a display-safe offer summary. Lookups always answer HTTP 200 with { valid, reason, offer } so a landing page can render the outcome honestly — including why an offer is not redeemable ('not_found' | 'inactive' | 'not_started' | 'expired' | 'fully_redeemed'). offer is null only when reason is 'not_found'. The only 400 is omitting both query parameters. Rate-limited per IP (30 requests/minute).

Authentication

None — public endpoint. No API key and no session required.

Request Schema

JSON type shapeExpand
{
  "code": "string",
  "slug": "string"
}
Fields2Expand
code
stringoptional
Query parameter. The promo code to resolve (case-insensitive). One of code or slug is required — omitting both returns 400 invalid_request.
slug
stringoptional
Query parameter. The share-link landing slug to resolve (compared lowercased). When both code and slug are provided, slug wins.

Response Schema

JSON type shapeExpand
{
  "valid": "boolean",
  "reason": "string | null",
  "offer": {
    "code": "string",
    "offerKind": "string",
    "creditAmount": "number | null",
    "discountPercent": "number | null",
    "discountCapCents": "integer | null",
    "minTopupCents": "integer | null",
    "slug": "string | null",
    "appliesAtSignup": "boolean",
    "appliesAtReload": "boolean",
    "expiresAt": "string | null"
  }
}
Fields13Expand
valid
booleanrequired
true when the offer exists and is currently redeemable.
reason
string | nullrequired
Why the offer is NOT redeemable: 'not_found' | 'inactive' | 'not_started' | 'expired' | 'fully_redeemed'. null when valid is true.
offer
object
object — fields below
code
stringrequired
The canonical promo code.
offerKind
stringrequired
'credit' (adds balance instantly at redemption) | 'reload_discount' (a bonus applied to a future qualifying top-up).
creditAmount
number | nullrequired
USD dollars credited on redemption for a 'credit' offer; null for other kinds.
discountPercent
number | nullrequired
Bonus percent applied to a qualifying top-up for a 'reload_discount' offer; null for 'credit' offers.
discountCapCents
integer | nullrequired
Upper bound of the reload bonus in integer cents; null for 'credit' offers.
minTopupCents
integer | nullrequired
Minimum top-up in integer cents before the offer applies; null when there is no minimum.
slug
string | nullrequired
Landing-page slug — the offer's shareable page is /promo/<slug>. null when the offer has no landing page.
appliesAtSignup
booleanrequired
Whether the offer applies when a new user signs up with the code.
appliesAtReload
booleanrequired
Whether the offer applies at reload (top-up) time.
expiresAt
string | nullrequired
ISO timestamp after which the offer expires; null when it never expires.

Code Examples

Resolve a promo code (case-insensitive).

curl "$BASE/api/promotions/resolve?code=WELCOME10"

# Response — 200 OK
# {
#   "valid": true,
#   "reason": null,
#   "offer": {
#     "code": "WELCOME10",
#     "offerKind": "credit",
#     "creditAmount": 10,
#     "discountPercent": null,
#     "discountCapCents": null,
#     "minTopupCents": null,
#     "slug": "welcome",
#     "appliesAtSignup": true,
#     "appliesAtReload": true,
#     "expiresAt": null
#   }
# }

Resolve a landing-page slug (slug wins when both are sent).

curl "$BASE/api/promotions/resolve?slug=welcome"

# Same response shape as resolving by code. The /promo/welcome landing
# page uses exactly this call to render the offer.

Unknown or expired offers are 200s with valid:false; only a missing code AND slug is a 400.

# An unknown code is NOT an HTTP error — the lookup outcome is in the body:
curl "$BASE/api/promotions/resolve?code=NO-SUCH-CODE"

# Response — 200 OK
# { "valid": false, "reason": "not_found", "offer": null }

# An expired (or inactive / not-started / fully-redeemed) offer still returns
# its display-safe summary so a landing page can render an honest message:
# { "valid": false, "reason": "expired", "offer": { "code": "SUMMER24", ... } }

# Omitting BOTH query parameters is the only 400:
curl "$BASE/api/promotions/resolve"

# Response — 400 Bad Request
# { "error": { "message": "code or slug is required", "type": "invalid_request" } }
POST/api/billing/redeem-promo#

Redeem a promo code

Redeems a promo code for the signed-in user. A 'credit' offer credits your USD balance instantly; a 'reload_discount' offer records a claim that is applied automatically to your next qualifying top-up. Each user can redeem a given code at most once, and redemption caps are enforced atomically. Same-origin requests only (CSRF protection), rate-limited to 10 attempts/minute per user.

Authentication

Session cookie required (browser session) — not available with API keys.

Request Schema

JSON type shapeExpand
{
  "code": "string"
}
Fields1Expand
code
stringrequired
The promo code to redeem. Minimum 4 characters; letters, digits and hyphens only; case-insensitive.

Response Schema

JSON type shapeExpand
{
  "success": "boolean",
  "offerKind": "string",
  "creditAmount": "string",
  "newBalance": "string",
  "discountPercent": "string | null",
  "message": "string"
}
Fields6Expand
success
booleanrequired
true when the redemption (or discount claim) was recorded.
offerKind
stringrequired
'credit' | 'reload_discount'.
creditAmount
stringoptional
USD dollars credited, as a decimal string. Present only for 'credit' offers.
newBalance
stringoptional
Your updated USD balance, as a decimal string. Present only for 'credit' offers.
discountPercent
string | nulloptional
The claimed bonus percent, as a decimal string. Present only for 'reload_discount' offers.
message
stringoptional
Human-readable confirmation. Present only for 'reload_discount' offers.

Code Examples

Redeem a credit or reload-discount code with your browser session.

# Runs with your signed-in browser session cookie (see Authentication above).
curl -X POST $BASE/api/billing/redeem-promo \
  -H "Content-Type: application/json" \
  -b "authjs.session-token=<your browser session cookie>" \
  -d '{ "code": "WELCOME10" }'

# Response — 200 OK (credit offer: balance credited instantly)
# { "success": true, "offerKind": "credit", "creditAmount": "10", "newBalance": "12.50" }

# Response — 200 OK (reload_discount offer: claim saved, applied on your next top-up)
# {
#   "success": true,
#   "offerKind": "reload_discount",
#   "discountPercent": "20",
#   "message": "Discount saved — it will apply to your next reload."
# }

This endpoint reports errors as a flat { "error": "<message>" } body.

# Errors use a flat { "error": "<message>" } body on this endpoint.

# Response — 401 Unauthorized (no browser session)
# { "error": "Authentication required" }

# Response — 404 Not Found (unknown code)
# { "error": "Invalid promo code." }

# Response — 400 Bad Request (each returned as its own message):
# { "error": "You have already redeemed this promo code." }
# { "error": "This promo code is no longer active." }
# { "error": "This promo code has expired." }
# { "error": "This promo code is not active yet." }
# { "error": "This promo code has been fully redeemed." }

# Response — 429 Too Many Requests (more than 10 attempts/minute)
GET/api/referrals/me#

Your referral stats & share link

Returns the signed-in user's referral summary for the Share & Earn view: whether you are enrolled as a promoter, your shareable link, how many users you have referred, and your commission totals in integer cents. Enrollment is automatic when the Share & Earn program is enabled (your first call provisions your link); otherwise it is admin-managed. Non-enrolled users receive asPromoter:false with zeroed totals — never an error. The response shape is identical in every case.

Authentication

Session cookie required (browser session) — not available with API keys.

Response Schema

JSON type shapeExpand
{
  "data": {
    "asPromoter": "boolean",
    "shareUrl": "string | null",
    "referredCount": "number",
    "commission": {
      "accruedCashCents": "integer",
      "paidCashCents": "integer",
      "autoCreditedCents": "integer",
      "currency": "string"
    }
  },
  "generatedAt": "string"
}
Fields10Expand
data
object
object — fields below
asPromoter
booleanrequired
true when you are enrolled as a promoter. Enrollment is admin-managed — when false every other field is its zero/null state.
shareUrl
string | nullrequired
Your shareable referral link: a /promo/<slug> landing page when a landing-page offer exists, otherwise a tracked /r/<id> redirect that forwards visitors to signup. null when not enrolled.
referredCount
numberrequired
Users attributed to you. Attribution is first-wins: a user counts for at most one referrer, forever.
commission
object
object — fields below
accruedCashCents
integerrequired
Commission earned and owed to you, awaiting cash payout. Integer cents.
paidCashCents
integerrequired
Commission already paid out to you in cash. Integer cents.
autoCreditedCents
integerrequired
Commission automatically credited to your platform balance. Integer cents.
currency
stringrequired
Always 'USD'.
generatedAt
stringrequired
ISO timestamp of when the response was generated.

Code Examples

Read your own referral stats (enrolled and not-enrolled shapes shown).

# Runs with your signed-in browser session cookie (see Authentication above).
curl "$BASE/api/referrals/me" \
  -b "authjs.session-token=<your browser session cookie>"

# Response — 200 OK (enrolled promoter)
# {
#   "data": {
#     "asPromoter": true,
#     "shareUrl": "https://ainvented.com/r/9c1f4c1e-0000-4000-8000-000000000000",
#     "referredCount": 3,
#     "commission": {
#       "accruedCashCents": 1500,
#       "paidCashCents": 200,
#       "autoCreditedCents": 0,
#       "currency": "USD"
#     }
#   },
#   "generatedAt": "2026-07-01T12:00:00.000Z"
# }

# Response — 200 OK (not enrolled)
# {
#   "data": { "asPromoter": false, "shareUrl": null, "referredCount": 0,
#             "commission": { "accruedCashCents": 0, "paidCashCents": 0,
#                             "autoCreditedCents": 0, "currency": "USD" } },
#   "generatedAt": "2026-07-01T12:00:00.000Z"
# }
curl "$BASE/api/referrals/me"

# Response — 401 Unauthorized (no browser session)
# { "error": { "message": "Authentication required", "type": "auth_error" } }
Reference · 4 endpoints

Vector Stores

Use Ainvented as a vector store. A store is a named collection of documents in your project's vector space. Ingest documents (text, URL, or file) — they are chunked and embedded — then run semantic search, optionally with a RAG-generated answer.

In this section
  1. GuideOverview
  2. GuideNode.js client
  3. POSTCreate / list / get/api/v1/vector-stores
  4. POSTAdd / list documents/api/v1/vector-stores/{id}/documents
  5. GuideDocument metadata
  6. GuideSupported file types
  7. POSTQuery (search + RAG)/api/v1/vector-stores/{id}/query
  8. GuideMetadata filters
  9. DELETEDelete/api/v1/vector-stores/{id}
  10. GuideCost & metering
Cost
Creating, renaming, and listing a store is free. add document (embedding) and query (query embedding, plus generation when answer:true) consume tokens and are metered against your project's budget and token quota. There is no zero-token billable path. The usage you get back is the audited count the ledger booked for that call — the same number your consumption reports show — priced at your input rate, with embedding work sold at the embedding rate published on the pricing page when one is configured.

Node.js client (example)

Node 18+ can call the REST endpoints directly with its built-in fetch. This complete example creates a store, adds reusable text, checks every HTTP response, and runs a semantic query—no extra client library required:

quickstart.mjs — Node 18+, create → ingest → search
const headers = {
  Authorization: `Bearer ${process.env.API_KEY}`,
  'Content-Type': 'application/json',
}

async function request(path, options = {}) {
  const response = await fetch(`https://ainvented.com${path}`, { headers, ...options })
  if (!response.ok) throw new Error(`Ainvented API ${response.status}: ${await response.text()}`)
  return response.json()
}

const store = await request('/api/v1/vector-stores', {
  method: 'POST', body: JSON.stringify({ name: 'product-docs' }),
})
await request(`/api/v1/vector-stores/${store.id}/documents`, {
  method: 'POST', body: JSON.stringify({ text: 'Ainvented can store reusable knowledge.' }),
})
const result = await request(`/api/v1/vector-stores/${store.id}/query`, {
  method: 'POST', body: JSON.stringify({ query: 'How does it work?', top_k: 5, answer: true }),
})
console.log(result.answer, result.results)
POST/api/v1/vector-stores#

Create / list / get stores

Create a store (local, zero-cost — reserves a tag). GET /v1/vector-stores lists; GET /v1/vector-stores/{id} retrieves; POST /v1/vector-stores/{id} updates name/description; all are local.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "name": "string",
  "description": "string",
  "project_id": "uuid"
}
Fields3Expand
name
stringrequired
1–200
description
stringoptional
≤500
project_id
uuidoptional
; ignored when the API key is project-scoped

Response Schema

JSON type shapeExpand
{
  "id": "string (cuid)",
  "name": "string",
  "description": "string|null",
  "tag": "string (vs:<id>)",
  "status": "\"active\" | \"archived\"",
  "project_id": "uuid",
  "document_count": "number",
  "created_at": "ISO",
  "updated_at": "ISO"
}
Fields9Expand
id
string (cuid)
name
string
description
string|null
tag
string (vs:<id>)
status
"active" | "archived"
project_id
uuid
document_count
number
created_at
ISO
updated_at
ISO

Code Examples

Create a store.

curl -X POST "$BASE/api/v1/vector-stores" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"name":"product-docs","description":"Docs for RAG"}'

List active stores (?status=archived|all, ?limit, ?cursor, ?order).

curl "$BASE/api/v1/vector-stores" -H "Authorization: Bearer $API_KEY"
POST/api/v1/vector-stores/{id}/documents#

Add / list documents

Add a document via JSON (text or url) or multipart (file ≤100MB). Raw text is stored as a .txt document. Embedding tokens are metered. Very large text-heavy files may take up to 10 minutes to embed. GET lists documents (?status=ready|pending|failed|archived|all).

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "text": "string",
  "url": "string (url)",
  "file (multipart)": "binary",
  "title": "string",
  "tags": "string[]",
  "chunk_size": "int",
  "chunk_overlap": "int",
  "metadata": "object",
  "generate_metadata": "boolean"
}
Fields9Expand
text
string
raw text to embed (one of text/url/file)
url
string (url)
fetch + embed remote content
file (multipart)
binary
documents, code/config, images, audio, or ANY extension (best-effort text), ≤100MB
title
stringoptional
≤300
tags
string[]optional
extra tags ≤20
chunk_size
intoptional
chunk_overlap
intoptional
metadata
objectoptional
key→value pairs applied to EVERY chunk of this document; filter on them later with query metadata_filter. JSON body field for text/url; multipart `metadata` form field (a JSON-object string) for file. Optional & backward-compatible — omit it and the request is unchanged.
generate_metadata
booleanoptional
default false — when true, an LLM extracts semantic metadata for the document (topics, summary, keywords, entities, language) and merges it into every chunk's filterable metadata. This makes an extra, fully-audited model call billed cost-plus alongside embeddings; omit/false adds no cost. Multipart: `generate_metadata=true` form field.

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "store_id": "string",
  "kind": "\"text\"|\"url\"|\"file\"",
  "title": "string|null",
  "doc_uid": "string|null",
  "source": "string|null",
  "char_count": "number",
  "chunk_count": "number",
  "embed_tokens": "number",
  "status": "\"ready\"|\"failed\"",
  "error_code": "string|null",
  "created_at": "ISO"
}
Fields12Expand
id
string
store_id
string
kind
"text"|"url"|"file"
title
string|null
doc_uid
string|null
this document’s own identity, used as the delete selector. null on documents added before identities existed (those still delete by title/source).
source
string|null
char_count
number
chunk_count
number
embed_tokens
number
status
"ready"|"failed"
error_code
string|null
created_at
ISO

Code Examples

Embed a text blob.

curl -X POST "$BASE/api/v1/vector-stores/$SID/documents" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"text":"Ainvented can be used as a vector store.","chunk_size":800,"chunk_overlap":100}'

Attach filterable key→value metadata to every chunk (optional).

curl -X POST "$BASE/api/v1/vector-stores/$SID/documents" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"text":"Q4 revenue grew 12%.","metadata":{"team":"finance","year":2024}}'

Opt in to LLM-extracted topics/summary/keywords/entities (extra audited cost). Merged into every chunk and filterable.

curl -X POST "$BASE/api/v1/vector-stores/$SID/documents" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"text":"TaskFlow Pro is $12/seat; invoices are emailed monthly.","generate_metadata":true}'

Multipart file upload.

curl -X POST "$BASE/api/v1/vector-stores/$SID/documents" \
  -H "Authorization: Bearer $API_KEY" -F 'file=@/path/to/doc.pdf'

Multipart `metadata` form field — a JSON-object string. Malformed/non-object values are ignored (never an error).

curl -X POST "$BASE/api/v1/vector-stores/$SID/documents" \
  -H "Authorization: Bearer $API_KEY" \
  -F 'file=@/path/to/doc.pdf' -F 'metadata={"team":"finance","year":2024}'

Details

Per-chunk metadata (optional)

Attach arbitrary metadata (a JSON object of key→value pairs) when adding a document and it is stored on every chunk of that document. You can then narrow a search to matching chunks with the query metadata_filter (see below). Pass it as a JSON body field for text/url adds, or as a multipart metadata form field (a JSON-object string) for file uploads. A malformed or non-object multipart metadata value is silently ignored — never an error.

Optional & backward-compatible
metadata is fully optional. Omitting it sends the exact same request as before and ingests with no chunk metadata. Metadata is stored alongside the chunk and adds no model/LLM cost — embedding tokens are identical to the same add without metadata.

Supported file types

Uploads are chunked + embedded (text is extracted; audio is transcribed; images are embedded for visual search). Unknown extensions are ingested as best-effort plain text. Max 100 MB. Very large text-heavy files may take up to 10 minutes to embed.

  • 📄 Text & Office: .pdf .docx .pptx .xlsx .xls .csv .json .jsonl .txt .md
  • 💻 Code & config: .py .js .ts .tsx .jsx .java .cpp .c .h .cs .php .rb .go .rs .swift .kt .scala .r .sh .bash .sql .xml .yaml .yml .toml .ini .cfg .conf .css .scss .sass .less
  • 🖼️ Images: .png .jpg .jpeg .gif .webp .bmp .tiff .svg
  • 🔊 Audio: .mp3 .wav .m4a .ogg .flac .aac
  • 🎬 Video: .mp4 .mov .webm .mkv .avi .3gp .mpeg .flv .wmv — up to 50 MB (413 video_too_large above it). Read as a text record (summary, timestamped visual timeline with on-screen text, transcript) that is chunked and searchable like any document.
  • 🌐 Web: pass url (JSON body) for an HTTP/HTTPS page — text plus extracted images/audio. A link to a video file, or a public YouTube link, is read as a video.
How images & audio behave
Audio is transcribed to text and then chunked like any document. An image is embedded for cross-modal (text→image) retrieval and stored with doc_type:"image", char_count:0 and chunk_count:0 — it carries no text chunk, so it matches on visual similarity, not keywords. Use an on-topic query and a low/zero threshold so a purely visual image ranks alongside text chunks; each result includes image_b64 for rendering.
POST/api/v1/vector-stores/{id}/query#

Query — semantic search (+ optional RAG answer)

Embeds the query and returns ranked chunks. Set answer:true to also generate a grounded answer from the retrieved chunks (a second, billable generation step). optimize_query:true adds a billable query rewrite.

Authentication

Bearer <api_key>

Request Schema

JSON type shapeExpand
{
  "query": "string",
  "top_k": "int",
  "threshold": "number",
  "optimize_query": "boolean",
  "tags": "string[]",
  "answer": "boolean (optional",
  "max_tokens": "int",
  "metadata_filter": "Array<{ key: string, op?: \"eq\"|\"neq\"|\"in\"|\"contains\"|\"gt\"|\"gte\"|\"lt\"|\"lte\"|\"exists\"|\"not_exists\", value?: any }> . AND-ed pre-filters applied BEFORE the semantic search: the matching chunks are selected first and ranked exactly by similarity, so a chunk that matches is never dropped by the approximate index",
  "text_contains": "string"
}
Fields9Expand
query
stringrequired
≤10000
top_k
intoptional
1–100
threshold
numberoptional
0–1 similarity cutoff; default 0: every chunk that survives the filters, ranked best first; raise it to drop weak matches
optimize_query
booleanoptional
; extra cost
tags
string[]optional
extra tag filter
answer
boolean (optional
generate a RAG answer)
max_tokens
intoptional
answer length cap
metadata_filter
Array<{ key: string, op?: "eq"|"neq"|"in"|"contains"|"gt"|"gte"|"lt"|"lte"|"exists"|"not_exists", value?: any }> . AND-ed pre-filters applied BEFORE the semantic search: the matching chunks are selected first and ranked exactly by similarity, so a chunk that matches is never dropped by the approximate indexoptional
≤20 — a document is filterable the moment it is "ready". op defaults to "eq"; "exists"/"not_exists" take no value; "in" takes an array; a boolean or number value compares as stored (true, 42). threshold defaults to 0, so a filtered query lists every matching chunk ranked by similarity; set it above 0 to cut weak matches. Optional & backward-compatible.
text_contains
stringoptional
≤500 — keep only chunks whose text contains this substring (applied before the semantic search). Optional & backward-compatible.

Response Schema

JSON type shapeExpand
{
  "results": "[{ text, title, source, score, metadata, ... }]",
  "count": "number",
  "answer": "string (only when answer:true)",
  "usage": {
    "total_tokens": "number"
  }
}
Fields5Expand
results
[{ text, title, source, score, metadata, ... }]
each chunk now carries the metadata it was ingested with (object, may be empty/absent)
count
number
answer
string (only when answer:true)
usage
object
object — fields below
total_tokens
number
the audited, billable count for the search (embedding, plus generation when answer:true); identical to what your consumption reports show for this call

Code Examples

Top-3 semantic search.

curl -X POST "$BASE/api/v1/vector-stores/$SID/query" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"query":"How do I use Ainvented as a vector store?","top_k":3}'

Map-reduce pre-filter: AND-ed metadata predicates + a text substring, applied before the semantic search (optional).

curl -X POST "$BASE/api/v1/vector-stores/$SID/query" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"query":"revenue","top_k":5,
       "metadata_filter":[{"key":"team","op":"eq","value":"finance"},
                          {"key":"year","op":"gte","value":2024}],
       "text_contains":"Q4"}'

Search + grounded answer.

curl -X POST "$BASE/api/v1/vector-stores/$SID/query" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"query":"Summarize the docs","answer":true,"max_tokens":150}'

Details

Map-reduce pre-filters (optional)

metadata_filter is an array of AND-ed predicates (≤20), each { key, op?, value? }. Supported op values: eq (default) neq in contains gt gte lt lte exists not_exists. exists and not_exists test for the presence/absence of the key and take no value; in takes an array of values. text_contains (≤500 chars) keeps only chunks whose text contains that substring. Both are applied before the semantic search (the “map” step), then the usual top_k/threshold ranking runs over what survives.

Optional, backward-compatible & no extra cost
Both fields are optional. Omitting them reproduces the exact legacy search(identical request and behaviour). Filtering happens upstream before the vector search, so it adds no model/LLM cost — the query embedding is unchanged whether or not you filter. Each query is billed exactly once against the calling project.
DELETE/api/v1/vector-stores/{id}#

Delete a store or a document

DELETE /v1/vector-stores/{id} deletes the store and removes its documents from search. DELETE /v1/vector-stores/{id}/documents/{docId} removes a single document — precisely that one, even when other documents share its filename.

Authentication

Bearer <api_key>

Response Schema

JSON type shapeExpand
{
  "id": "string",
  "status": "\"archived\"",
  "deleted": "true",
  "collateral_archived": "number (document delete only)"
}
Fields4Expand
id
string
status
"archived"
deleted
true
collateral_archived
number (document delete only)
how many OTHER documents were archived alongside this one. Always 0 for documents carrying a doc_uid. See below.

Code Examples

Archive a store.

curl -X DELETE "$BASE/api/v1/vector-stores/$SID" -H "Authorization: Bearer $API_KEY"

Removes exactly this document, whatever else shares its filename.

curl -X DELETE "$BASE/api/v1/vector-stores/$SID/documents/$DOC_ID" \
  -H "Authorization: Bearer $API_KEY"
# => {"id":"...","status":"archived","deleted":true,"collateral_archived":0}

Details

Deleting one document among duplicates

Uploading the same file twice creates two documents, with the same title and source but different ids. Each carries its own doc_uid, and a delete matches on that — so removing one copy never touches the other, and collateral_archived comes back 0.

Documents added before doc_uid existed
A document whose doc_uid is null predates per-document identities, so its chunks can only be matched by title + source. Deleting it therefore also removes the chunks of every other doc_uid: null document with the same title — those rows are archived with it and counted in collateral_archived, so the response tells you exactly what went. Documents added since are never affected: they carry an identity and stay out of range. Check doc_uid before a bulk clean-up if you need to know which is which.

Cost & metering

Adding a document, searching, and generating an answer each consume tokens that are metered against your project's budget and token quota — one usage event per billable call, so your Consumption totals always match what you actually used. Local operations (create, rename, list, delete) are free.

Reference · 5 endpoints

Webhooks

Register HTTPS endpoints to receive notifications when a project crosses a budget threshold (50%, 80%, 95%, 100% by default), exhausts its budget, or — opt-in — on every recorded usage event. Deliveries are signed with HMAC-SHA256 over the raw body using the secret returned at registration. Each delivery is idempotent on a payload hash so retries do not duplicate. URLs must be https:// and cannot resolve to RFC1918 / loopback / link-local / multicast addresses.

In this section
  1. POSTRegister/api/v1/projects/{projectId}/webhooks
  2. GETList/api/v1/projects/{projectId}/webhooks
  3. PUTUpdate / rotate secret/api/v1/projects/{projectId}/webhooks/{webhookId}
  4. DELETEDelete/api/v1/projects/{projectId}/webhooks/{webhookId}
  5. POSTTest fire/api/v1/projects/{projectId}/webhooks/{webhookId}/test
  6. GuidePayload & signature
POST/api/v1/projects/{projectId}/webhooks#

Register a webhook

Creates a webhook registration. The signing secret is returned ONCE in the response and is never readable again — store it securely.

Authentication

Bearer <api_key> — must own the project. Project must not be disabled.

Request Schema

JSON type shapeExpand
{
  "url": "string",
  "events": "(\"budget.threshold\" | \"budget.exhausted\" | \"tokens.threshold\" | \"tokens.exhausted\" | \"usage.recorded\")[]"
}
Fields2Expand
url
stringrequired
https://, no credentials, ≤2048 chars, public IP only
events
("budget.threshold" | "budget.exhausted" | "tokens.threshold" | "tokens.exhausted" | "usage.recorded")[]optional
default ["budget.threshold","budget.exhausted"]

Response Schema

JSON type shapeExpand
{
  "id": "uuid",
  "url": "string",
  "events": "string[]",
  "is_active": "boolean",
  "secret": "string",
  "created_at": "ISO"
}
Fields6Expand
id
uuid
url
string
events
string[]
is_active
boolean
secret
string
64 hex chars; returned only once
created_at
ISO

Code Examples

curl -X POST $BASE/api/v1/projects/$PID/webhooks \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://hooks.your-app.com/budget", "events": ["budget.threshold","budget.exhausted"] }'
GET/api/v1/projects/{projectId}/webhooks#

List webhooks

Lists the project's active webhooks. Secrets are NEVER returned by list.

Authentication

Bearer <api_key> — must own the project.

Response Schema

JSON type shapeExpand
{
  "data": [
    {
      "id": "uuid",
      "url": "string",
      "events": "string[]",
      "is_active": "boolean",
      "created_at": "ISO",
      "last_delivery_at": "ISO | null",
      "failure_count": "number"
    }
  ]
}
Fields8Expand
data
array
array — fields below
id
uuid
url
string
events
string[]
is_active
boolean
created_at
ISO
last_delivery_at
ISO | null
failure_count
number

Code Examples

curl $BASE/api/v1/projects/$PID/webhooks -H "Authorization: Bearer $API_KEY"
PUT/api/v1/projects/{projectId}/webhooks/{webhookId}#

Update a webhook (incl. rotate secret)

Patches url, events, or is_active. Pass rotate_secret: true to issue a new signing secret — the new secret is returned ONCE in the response and the old one stops verifying immediately. Empty patch returns 400.

Authentication

Bearer <api_key> — must own the project.

Request Schema

JSON type shapeExpand
{
  "url": "string",
  "events": "string[]",
  "is_active": "boolean",
  "rotate_secret": "boolean"
}
Fields4Expand
url
stringoptional
https-only same rules as register
events
string[]optional
is_active
booleanoptional
rotate_secret
booleanoptional

Response Schema

JSON type shapeExpand
{
  "id": "uuid",
  "url": "string",
  "events": "string[]",
  "is_active": "boolean",
  "secret": "string (only present when rotate_secret was true)"
}
Fields5Expand
id
uuid
url
string
events
string[]
is_active
boolean
secret
string (only present when rotate_secret was true)

Code Examples

curl -X PUT $BASE/api/v1/projects/$PID/webhooks/$WH_ID \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "rotate_secret": true }'
DELETE/api/v1/projects/{projectId}/webhooks/{webhookId}#

Delete a webhook

Stops all deliveries to the webhook. Idempotent: a second call returns 410.

Authentication

Bearer <api_key> — must own the project.

Code Examples

curl -X DELETE $BASE/api/v1/projects/$PID/webhooks/$WH_ID -H "Authorization: Bearer $API_KEY"
POST/api/v1/projects/{projectId}/webhooks/{webhookId}/test#

Test fire a webhook

Sends a synthetic budget.threshold payload to the registered URL with the same signing scheme as production deliveries. Useful for verifying signature handling on the receiving side.

Authentication

Bearer <api_key> — must own the project. Webhook must be active.

Response Schema

JSON type shapeExpand
{
  "delivered": "boolean",
  "attempts": "number"
}
Fields2Expand
delivered
boolean
attempts
number

Code Examples

curl -X POST $BASE/api/v1/projects/$PID/webhooks/$WH_ID/test \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
Guide

Webhook payload & signature

Every delivery sends the following headers and a JSON body. Verify the signature using HMAC-SHA256 over the raw request body with the webhook's secret.

  • X-Ainvented-Event — event type, e.g. budget.threshold
  • X-Ainvented-Delivery — unique delivery UUID
  • X-Ainvented-Signature — sha256=<hex> over the raw body
  • User-Agent — Ainvented-Webhook/1.0
budget.threshold delivery
{
  "id": "<delivery uuid>",
  "event": "budget.threshold",
  "occurred_at": "2026-04-29T10:30:00Z",
  "project_id": "<uuid>",
  "data": {
    "currency": "USD",
    "budget_cents": 25000,
    "consumed_cents": 20000,
    "remaining_cents": 5000,
    "remaining_pct": 20.0,
    "threshold_pct": 80,
    "by_component": {
      "completion": { "events": 412, "total_tokens": 88000, "cost_cents": 9100 },
      "workflow":   { "events": 33,  "total_tokens": 21000, "cost_cents": 4200 },
      "skill":      { "events": 71,  "total_tokens": 11334, "cost_cents": 2500 },
      "assistant":  { "events": 18,  "total_tokens":  3000, "cost_cents": 1520 }
    }
  }
}

Token-quota events (tokens.threshold / tokens.exhausted) fire when consumed_tokens crosses one of the project's alert_thresholds percentages of token_limit. Each threshold fires at most once per re-arm cycle (re-arm happens automatically when token_limit or alert_thresholds is updated). Payload shape:

tokens.threshold delivery
{
  "id": "<delivery uuid>",
  "event": "tokens.threshold",
  "occurred_at": "2026-05-14T16:00:00Z",
  "project_id": "<uuid>",
  "data": {
    "currency": "USD",
    "token_limit":      1000000,
    "consumed_tokens":   800000,
    "remaining_tokens":  200000,
    "remaining_pct":     20.0,
    "threshold_pct":     80,
    "by_component": {
      "completion": { "events": 412, "total_tokens": 660000, "cost_cents": 9100 },
      "workflow":   { "events": 33,  "total_tokens":  90000, "cost_cents": 4200 }
    }
  }
}

Reliability: 3 retries with exponential backoff (1 s, 4 s, 16 s). Each delivery is recorded in ProjectWebhookDelivery; the payloadHash column makes deliveries idempotent so retries never duplicate. Webhooks are auto-disabled after 20 consecutive failures.

Reference

Error Codes

Every failure, on every endpoint, comes back in the same envelope. type names the family, code the specific reason and param the field that caused it when there is one.

Error envelope
{
  "error": {
    "message": "string - Human-readable error message",
    "type": "string - Error type (see Error Codes section)",
    "param": "string (optional) - Parameter that caused the error",
    "code": "string (optional) - Specific error code"
  }
}
400

Bad Request

invalid_request_error

Description: The request is malformed or contains invalid parameters. This includes validation errors for multimodal content (invalid base64, unsupported formats, size limits exceeded) and for image-generation inputs (see image-gen specific codes below).

context_length_exceeded (param: "messages") — the prompt is larger than the selected model tier's input budget and could not be trimmed without cutting your own messages. The message states how many input tokens the request needs and how many are available. This refusal is NOT billed: it is decided before the model is called, so no tokens are consumed and no usage is recorded. Retry with fewer or shorter messages, fewer attached files, or a tier with more headroom. Requests that can be trimmed succeed instead and report what was dropped on the context_truncation response field.

Image-generation specific codes (all return 400 with type invalid_request_error):

  • image_modality_unsupported — modalities contained a value other than text/image.
  • invalid_modalities — modalities was null or not an array.
  • image_count_out_of_range — image.n was outside 1..4 or not an integer.
  • image_size_unsupported — image.size was not one of the seven allowed values (256x256, 512x512, 1024x1024, 1024x1536, 1536x1024, 1024x1792, 1792x1024).
  • invalid_quality / invalid_style / invalid_response_format — corresponding image.* field had an unsupported value.
  • invalid_remove_background — image.remove_background was not a boolean.
  • invalid_image_block — image was not a plain object.
  • invalid_image — an input image of the request (a reference image for the picture) could not be read: the file is damaged or cut short. Never billed; send the image again in one of the accepted formats. A retry of the same file cannot succeed.

502 image-generation specific codes (with type service_unavailable):

  • image_generation_failed — image generation returned a non-OK status, an empty image list, or fewer images than requested (partial failure = failure).
  • image_background_removal_failed — background removal returned a non-OK status or an invalid response (when background removal is enabled for your project).
  • empty_response / partial_failure / upstream_<status> / fetch_error — finer-grained sub-codes that appear in the code field of an image_generation_failed envelope.

A picture that was not made is not billed. When image generation is momentarily busy, the 502 carries a Retry-After header (seconds, at most 60): wait that long before retrying; without it, retry with exponential backoff. A picture the project's budget or token quota refuses is not a 502: it is the 402 every refusal of this endpoint answers (insufficient_balance or insufficient_token_quota) — nothing is made or billed, and a retry cannot succeed until the project is funded. A picture is billed at the standard rate, whatever model the request names.

Video codes (400, never billed): invalid_video_url, unsupported_format, video_too_large, too_many_videos, video_unavailable (an explicitly attached link could not be downloaded, or a YouTube link to a video that does not exist, was removed or is private), video_content_rejected (the video may contain restricted content). See Video Content.

Structured output and reasoning (400, never billed): invalid_response_format (param: "response_format") — the value is not one of the three forms, a strict schema breaks a strict-mode rule (the message names it), or it was combined with modalities: ["image"]; invalid_reasoning_option — include_reasoning is not a boolean, or reasoning is not an object with a boolean exclude. See Structured output.

Voice (400, never billed): invalid_model, invalid_input, input_too_long, invalid_language, invalid_speed, invalid_response_format, invalid_file, invalid_file_type, consent_required, voice_read_only, project_mismatch; 413 file_too_large; 404 voice_not_found / voice_project_not_found / generation_not_found; 409 voice_project_archived / duplicate_name. See Voice.

Decisions (400, never billed): invalid_input, invalid_question, too_many_questions, input_too_long, questions_required, project_mismatch, project_missing; on chat completions, unsupported_model for the decision model (it does not chat); 404 decision_project_not_found / run_not_found; 409 decision_project_archived / duplicate_name. See Decisions.

Guardrails and skills (400, never billed): on chat completions, invalid_guardrail / invalid_skill (param names the tools entry), too_many_guardrails / too_many_skills, inline_directives_too_large, guardrail_not_found / skill_not_found and ambiguous_guardrail / ambiguous_skill for a stored one selected by id or name; on the project endpoints, 404 guardrail_not_found / skill_not_found, 409 duplicate_name, 409 guardrail_limit_reached / skill_limit_reached, 403 admin_key_required for a project-scoped key. See Guardrails & Skills.

Handling: Check the error message and param field to identify which parameter is invalid. Validate your request against the schema. For multimodal content, ensure proper base64 encoding, supported formats, and size limits.

401

Unauthorized

authentication_error

Description: Authentication failed. Invalid, missing, or revoked API key. One exception is not about your key: upstream_unavailable (type server_error) on chat completions or workflow execution is a temporary platform-side problem.

Handling: Verify your API key is correct and hasn't been revoked. Ensure the Authorization header is properly formatted: Bearer YOUR_API_KEY. For upstream_unavailable, keep the key and retry with backoff — nothing was billed.

403

Forbidden

permission_error

Description: Insufficient permissions to access the requested resource. Image-gen specific: image_generation_disabled fires when the request explicitly opted in to image output via modalities/tools but image generation is disabled for the project.

Handling: Verify you own the project you're trying to access. Check that your API key has permission for the requested operation. For image_generation_disabled, enable image generation in the AI Chat → Configure pane → "Image Generation" toggle, or remove 'image' from modalities.

404

Not Found

not_found_error

Description: The requested resource doesn't exist or doesn't belong to your API key.

Handling: Verify the project ID or session ID exists and belongs to your API key. For sessions, ensure you're using a session ID from a previous response.

429

Too Many Requests

rate_limit_error

Description: Rate limit exceeded for your API key.

Handling: Implement exponential backoff. Check the Retry-After header for seconds until reset. Monitor rate limit headers to avoid hitting limits.

429

Server At Capacity

server_overloaded

Description: Distinct from the per-key rate limit above. Under sustained high concurrency a node may briefly shed new requests to protect the requests already in flight (load-shedding / admission control). The request was not processed, reached no AI model, and incurred no token cost — it is fully safe to retry.

Handling: Honor the Retry-After header and retry with backoff. Because the request did nothing, retrying does not double-bill. Most chat-completions client libraries already do this for you — typically two retries of a 429 by default, each after what Retry-After says, which on this refusal is when the service expects to admit again — so raise their retry count to ride out a longer spike.

451

Not Available In Your Region

permission_error

Description: region_not_supported — the request comes from a country the platform does not serve (judged by the client's network address; for messaging, by the phone number's country). The request was not processed, reached no AI model and is not billed. A WhatsApp or SMS send to a number in such a country answers the same code and nothing is sent.

Handling: Do not retry — the answer will not change. Webhooks, cron and health endpoints are never affected.

500

Internal Server Error

server_error

Description: An unexpected error occurred on the server.

Handling: Retry the request with exponential backoff. If the error persists, contact support with the error ID from the response.

502

Upstream Error

service_unavailable

upstream_error — the AI service could not answer this turn right now (it was momentarily busy or failing). The turn was not answered and is not billed — except a video read for it, which is billed once and kept, so the retry does not pay for it again.

Handling: Retry. When the answer carries a Retry-After header (seconds, at most 60), wait that long first — it says when the service expects to answer again; without it, retry with exponential backoff.

502

Response Format Not Met

service_unavailable

response_format_failed — every generation of a turn with response_format failed validation (a bounded number of attempts was made). The generations are billed like any other turn. Retry the request; if it keeps failing, simplify the schema or give the model clearer instructions about the keys you expect.

503

Service Unavailable

service_unavailable

Description: The service is temporarily unavailable due to maintenance or overload.

video_processing_unavailable — a message's video could not be read because video reading was momentarily unavailable. Nothing reached the model and nothing is billed; any video that was already read is cached, so the retry does not pay for it again.

voice_unavailable (503) / voice_timeout (504) — speech, design or transcription could not be completed right now. A failed voice call is not billed; retry.

Handling: Retry after a delay (honor Retry-After). Check status page for maintenance announcements.

Reference

Best Practices

The habits that keep an integration fast, cheap and safe.

  • Error handling

    Always implement proper error handling for all HTTP status codes. Parse error responses to provide meaningful feedback to users.

  • Rate limiting

    Monitor rate limit headers and implement exponential backoff when approaching limits.

  • Session management

    Reuse session IDs for multi-turn conversations to maintain context. Store session IDs securely on your backend.

  • Streaming

    Use streaming mode for better user experience with long responses. Handle SSE parsing correctly and display tokens as they arrive.

  • Security

    Never expose API keys in client-side code. Always make API calls from your backend. Rotate keys regularly and revoke compromised keys immediately.

  • Timeouts

    Set appropriate timeouts for your requests (recommended: 60 seconds for completions).

  • Multimodal content

    Compress images and audio before encoding to reduce token usage. Use appropriate detail levels for images ('low' for simple recognition, 'high' for detailed analysis). Monitor size limits and handle validation errors gracefully.

Reference

Additional Resources

Where to go next.

  • API Key ManagementCreate, rotate and revoke your API keys.
  • Chat projectsCreate and configure the projects these endpoints manage.
  • ObservabilityPer-request traces, latency and cost, matched to X-Request-Id.
  • BillingYour balance, invoices and project budgets.
  • contact@ainvented.comAccess to the reseller surface (payments, WhatsApp) and anything this reference leaves unanswered.