Skip to content

Knowledge API

Sources the assistant answers from, and pushing your own records.

The same operations are in the interactive API reference, and the whole contract is in the OpenAPI document.

POST/v1/knowledge/ask

Ask the assistant a question

Has the organization's assistant answer one question from its public knowledge, for your own app or chatbot. It uses the same knowledge, rules, "I do not know" policy and check against made-up numbers as the chat assistant. It has no tools, so it can never act: it cannot place a call, send a message or change anything.

Send question (1 to 2000 characters) and, for a conversation, the earlier turns as history, oldest first, as [question, answer] pairs; only the last 40 are used. Send contact_id when your app knows who is asking. answered is false when the knowledge had no answer, and then answer says so in the assistant's own words. Treat answered: false as a prompt to hand over to a person, not as an error.

Needs the knowledge:read scope. This is a POST, but it changes no knowledge. It makes one model call, charged like one chat turn, and the turn is recorded under conversations as coming from the API. A test key is answered from the sandbox's knowledge and charges nothing; a live key is charged from credit. Repeating a request with the same Idempotency-Key returns the first answer instead of asking the model again. Use search instead when you want the facts themselves and no model call.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
Idempotency-KeyheaderstringNoMakes a POST safe to repeat: the same key returns the first result for 24 hours. The same key with a different body is refused with `422 idempotency_key_reused`; while the first request still runs, `409 idempotency_in_progress`.
X-Brain-DebugheaderstringNoSend `1` to get a `debug` object with the answer. Only a test key or staff get it; for any other caller the header is ignored.

GET/v1/knowledge/connections

List website connections

Returns the websites AirFone reads for this organization, oldest first, a page at a time. Each has its status (active, paused, broken), whether a sync is running, waiting_for_credit (true for a website that is due but not read because the organization has no credit; it starts by itself once credit is added), when it last synced and when it is next due, how many syncs failed in a row, and how many unusable rows are waiting. Connections being removed are not listed.

A connection is a place AirFone reads on a schedule, with no model calls: a website is crawled, every page is kept as it was fetched, read by rules into facts, and the rest is kept as searchable passages. Files and spreadsheets appear here too once set up in the console. To see what a connection has taught, use its detail and items operations. Records you push yourself are a different thing, see sources.

Needs the knowledge:read scope. Page with cursor (the previous page's next) and limit (1 to 200, 50 when left out; out of range values are clamped).

Scope knowledge:read. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
cursorquerystringNoThe `next` of the previous page. Pass it back unchanged.
limitqueryintegerNoHow many items to return, 1 to 200. 50 when left out.

POST/v1/knowledge/connections

Connect a website

Adds a website that AirFone will read and keep up to date, and starts its first sync at once. Only kind: website is accepted through the API for now; files and spreadsheets are added in the console.

url is the address to start from. scope is site (the default: follow links across the site) or page (read only this address, for example one article). depth is how many link hops to follow, 1 to 5 (3 by default), and max_pages is the most pages to read, 1 to 5,000 (500 by default); the organization's quota applies on top. schedule is manual, daily or weekly (the default). audience is who may hear what is learned: public (the default), customers or staff. name is optional and defaults to the host.

A new connection answers 202 with {id, created: true}. Adding a site that is already connected is not an error: it answers 200 with the existing id and created: false, and changes nothing, so a retried request is safe. A page connection is matched on its own address, so many pages of one site can each be a connection. The address must be public; addresses on private networks and sites AirFone cannot read are refused with 400. An organization may have at most 25 connections; beyond that the request is refused with 403.

Changing knowledge needs the knowledge:write scope, and the caller must act as an admin of the organization. Anyone else gets 403. A test key reads and changes the sandbox's knowledge and a live key the live knowledge; they never mix. Send an Idempotency-Key so a retried request does not repeat the action.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
Idempotency-KeyheaderstringNoMakes a POST safe to repeat: the same key returns the first result for 24 hours. The same key with a different body is refused with `422 idempotency_key_reused`; while the first request still runs, `409 idempotency_in_progress`.

GET/v1/knowledge/connections/{id}

Get one connection

Returns one connection in full: where it reads from (the address, scope and limits for a website, the files for an upload), counts of what it has taught (items, passages, records, facts, objects), what a running sync has done so far, and the last finished run.

Use progress while syncing is true to show how far a first crawl has got. paused_reason is set when AirFone paused the connection, for example after repeated failures, and null when the owner paused it. counts.dead_letters are spreadsheet rows that could not be used and are still waiting.

Needs the knowledge:read scope. A connection that does not exist, or has been removed, is a 404. A connection whose audience is staff looks like a 404 to callers who are not an admin or a developer.

Scope knowledge:read. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
idpathstringYesThe resource id.

PATCH/v1/knowledge/connections/{id}

Update a connection

Changes a connection's name, schedule, audience or whether it runs. Send only the fields you want to change. schedule is manual, daily or weekly. audience is public, customers or staff. status is active or paused; pausing stops scheduled syncs, and setting active again clears the last error and makes the next sync due at once if none was scheduled.

A new audience takes effect at once for everything the connection has already taught, not only for future syncs, and the answer says rescoped: true. Move a connection to staff before you correct a mistake, not after. Any other value for schedule, audience or status is a 400. A connection that is being removed, or does not exist, is a 404.

Changing knowledge needs the knowledge:write scope, and the caller must act as an admin of the organization. Anyone else gets 403. A test key reads and changes the sandbox's knowledge and a live key the live knowledge; they never mix. The same change sent twice is harmless.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
idpathstringYesThe resource id.

DELETE/v1/knowledge/connections/{id}

Remove a connection

Starts removing a connection and everything it taught, and returns at once. A worker then retires its records and passages in batches and finally marks the connection removed. The history of what was known is kept, so the removal can be seen in an object's history. Facts from this connection stop answering as soon as the worker reaches them, and anything they replaced answers again.

The server answers 202 Accepted with {removing: true}. Removing again while the removal is running gives the same answer; once it has finished the connection no longer exists and the answer is 404.

Changing knowledge needs the knowledge:write scope, and the caller must act as an admin of the organization. Anyone else gets 403. Because this cannot be taken back, a signed-in person must also have entered their password recently, otherwise the answer is 403 with code reauthentication_required. An API key is not asked for that. If the aim is to undo one bad sync rather than forget the whole site, use rollback instead. A test key reads and changes the sandbox's knowledge and a live key the live knowledge; they never mix.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
idpathstringYesThe resource id.

GET/v1/knowledge/connections/{id}/item

Get one item of a connection

Returns everything one item became: the original (as text for text formats), the document read from it as blocks (headings, paragraphs, lists, tables), the passages it was cut into, and the records and facts it produced with the objects they describe. It is how you answer "why does the assistant say this".

key is the item's id from the items list: a page address, file:{id} for an uploaded file, or a row key for a spreadsheet. Large parts are capped and say so in truncated and facts_truncated; the original can be downloaded whole with the raw operation. An empty or over-long key (more than 4,096 characters) is a 400.

Needs the knowledge:read scope. An unknown connection is a 404. Items of a connection whose audience is staff can be read only by an admin or a developer; for anyone else the connection looks like a 404.

Scope knowledge:read. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
idpathstringYesThe resource id.
keyquerystringYesThe item's `id` from the items list: a page address, `file:{id}`, or a row key. Up to 4,096 characters.

GET/v1/knowledge/connections/{id}/item/raw

Download the original of an item

Returns the item exactly as it was fetched or uploaded, decrypted, as a download (not JSON). The content type is the original's. Originals are kept encrypted under the organization's own key and are decrypted only for this call.

key is the item's id from the items list. The answer is a 404 when the connection is unknown, when the connection's audience is staff and the caller is not an admin or a developer, or when no original is archived for the item, which is the case for items that failed before they were stored.

Needs the knowledge:read scope. The download can be large; read the item detail first if you only need the text.

Scope knowledge:read. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
idpathstringYesThe resource id.
keyquerystringYesThe item's `id` from the items list: a page address, `file:{id}`, or a row key. Up to 4,096 characters.

GET/v1/knowledge/connections/{id}/items

List the items of a connection

Returns the items a connection has read, in a stable order by id, a page at a time: for a website each page, for an upload each file. For each item you get its address, how many records and passages it gave, its flags, how many times it was missing from a sync or failed, the last error, when it was last seen and when it went away.

status narrows the list to current, missing, gone, failed or pending; all or nothing returns every item. limit is 1 to 500 (100 when left out); outside that range is a 400. Page with after, the last id of the previous page, and the answer's next for the following one. An unknown status is a 400.

Needs the knowledge:read scope. An unknown or removed connection is a 404.

Scope knowledge:read. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
idpathstringYesThe resource id.
afterquerystringNoThe last `id` of the previous page.
limitqueryintegerNoHow many items to return, 1 to 500. 100 when left out.
statusquerystringNoOnly items in this state.

POST/v1/knowledge/connections/{id}/rollback

Roll a connection back

Undoes what a bad sync of one connection taught. Send since, an RFC 3339 time. Every fact this connection wrote at or after that time is closed, and the facts those replaced answer again. The answer is {closed, restored}, the number of facts closed and the number brought back.

Nothing is deleted: the closed facts stay in the history and the connection keeps running. If the next sync reads the same bad content it will write the same facts again, so fix or pause the connection first. A since in the future closes nothing and returns zeros. For a source you push records into, use the rollback under sources.

Changing knowledge needs the knowledge:write scope, and the caller must act as an admin of the organization. Anyone else gets 403. A test key reads and changes the sandbox's knowledge and a live key the live knowledge; they never mix. Rolling back to the same time twice does nothing the second time, so a retry is safe. The connection id is not checked for existence: an unknown id returns zeros rather than 404. Send an Idempotency-Key so a retried request does not repeat the action.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
idpathstringYesThe resource id.
Idempotency-KeyheaderstringNoMakes a POST safe to repeat: the same key returns the first result for 24 hours. The same key with a different body is refused with `422 idempotency_key_reused`; while the first request still runs, `409 idempotency_in_progress`.

GET/v1/knowledge/connections/{id}/runs

List a connection's sync runs

Returns the connection's sync log, newest first, the last 50 runs: when each started and ended, the outcome, what it saw and changed (stats), and the error if it failed. Use it to see why facts did or did not change, or why a connection went broken.

The answer is not paged; older runs are not available. Needs the knowledge:read scope. An unknown or removed connection is a 404.

Scope knowledge:read. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
idpathstringYesThe resource id.

POST/v1/knowledge/connections/{id}/sync

Sync a connection now

Asks for a sync of this connection as soon as possible, without waiting for its schedule. It also clears the failure count and returns a broken or paused connection to active, so it is the way to retry after you have fixed the cause of failures.

The server answers 202 Accepted with {queued: true}; the sync runs in the background and you follow it with the connection's detail (syncing, progress) or its runs. Asking while a sync is already running is fine: that sync notes the request and the next one starts at once when it ends, so there is never more than one run at a time. A connection that does not exist, or is being removed, is a 404.

A website is read only for an organization that has paid: wallet money, free welcome credit or a credit limit. Without any, this answers 402 insufficient_credit (or spending_limit_reached / spending_paused when a limit or a stop is the reason) and nothing is read. The connection stays and starts by itself once credit is added.

Changing knowledge needs the knowledge:write scope, and the caller must act as an admin of the organization. Anyone else gets 403. A test key reads and changes the sandbox's knowledge and a live key the live knowledge; they never mix. Repeating the request is harmless; it queues one more sync at most. Send an Idempotency-Key so a retried request does not repeat the action.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
idpathstringYesThe resource id.
Idempotency-KeyheaderstringNoMakes a POST safe to repeat: the same key returns the first result for 24 hours. The same key with a different body is refused with `422 idempotency_key_reused`; while the first request still runs, `409 idempotency_in_progress`.

POST/v1/knowledge/index/embedder

Point the search at an embedding space

Admin only. Points this organization's searches at another embedding space once its vectors are built, and back again to undo it. Leave space out to use the space the server's embedder fills. Moves the index version on, so every cache keyed by it drops. A space id is letters, digits and _, up to 24 characters.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

POST/v1/knowledge/index/rebuild

Rebuild the knowledge index now

Admin only. Re-projects the organization's knowledge and re-syncs its search index. A large site takes minutes, so the call waits up to 20 seconds and answers with the knowledge statistics as they are then; the rebuild goes on in the background.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

GET/v1/knowledge/missing

List what the assistant cannot answer yet

Returns things the assistant knows about but lacks a property callers usually ask for: a product with no price, a branch with no opening hours. The business itself is listed first. Each item names the object, its kind and the properties missing. At most 200 are returned, and the list is not paged.

It is a to-do list for whoever looks after the knowledge. The properties that count as required follow the organization's industry template; see the ontology. Fill a gap by pushing a record with the missing fact, or by adding it in the console, and the item leaves the list.

Needs the knowledge:read scope. Reading is free and changes nothing.

Scope knowledge:read. Accepts: API key or personal access token. Open in the API reference

GET/v1/knowledge/ontology

Get the ontology

Returns the kinds of things a business of this type has, the facts each kind can carry, the links between kinds, and the starting templates they come from. Use it to decide which kind and relation to use when you push records, so that what you push lines up with what the assistant already expects.

With no parameters you get the organization's own template, chosen at onboarding or by PUT /v1/vocab/industry. templates takes template keys separated by commas (for example clinic,shop), or all for every template. An unknown key is a 400.

Needs the knowledge:read scope. The ontology is reference data: it is the same for a test key and a live key and cannot be edited here.

Scope knowledge:read. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
templatesquerystringNoTemplate keys separated by commas, such as `clinic,shop`, or `all`. Left out, this organization's own template.

POST/v1/knowledge/search

Search the knowledge

Returns what the assistant would know for a question, without asking a model: facts from the knowledge graph as plain sentences, best first, and passages from websites and documents (public knowledge only). Use it to ground your own answers, or to check what the assistant would find before you ask it.

Send query (1 to 2000 characters). audience is public (the default, what any caller may hear), customers or staff; the last two need an admin, others get 403. limit is how many facts, 1 to 30 (8 by default); outside that range is a 400. passages is at most 3, and is empty when the search service is off or slow: the facts still come back, so treat an empty passages as normal.

Needs the knowledge:read scope. It is a POST so the question stays out of URLs and logs, but it has no side effects, makes no model call and counts nothing, and so is free. A test key reads and changes the sandbox's knowledge and a live key the live knowledge; they never mix. Sending an Idempotency-Key is allowed and harmless.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
Idempotency-KeyheaderstringNoMakes a POST safe to repeat: the same key returns the first result for 24 hours. The same key with a different body is refused with `422 idempotency_key_reused`; while the first request still runs, `409 idempotency_in_progress`.

GET/v1/knowledge/sources

List pushed sources

Returns the systems you push records from, each with how many of its records are current, how many were deleted, and when the last record arrived. A source exists once you push its first record; its name is the one you used in the path. Connections AirFone reads itself are not listed here, see connections.

Needs the knowledge:read scope. Paged, newest first: limit is 1 to 100 (default 50, out of range values are clamped) and cursor is the next_cursor of the previous page. The cursor is opaque and never built by the client; a cursor this API did not return is a 400. has_more is true while another page exists. There is no total.

Scope knowledge:read. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
limitqueryintegerNoHow many items to return. Default 50, at most 100.
cursorquerystringNoThe `next_cursor` of the previous page. Opaque; never built by the client.

POST/v1/knowledge/sources/{source}/records

Push a batch of records

Writes up to 500 records from one of your own systems in a single request. Use it for the first load and for periodic syncs. source is your name for the system: 1 to 60 characters of a-z, 0-9, - and _. It appears as the provenance of every fact the records produce.

Records are upserted by (source, external_id). The same content twice is a no-op (unchanged); a record older than the one held, by updated_at, never replaces it (stale); a record marked deleted or with deleted_at retires its facts (deleted). Relations a record used to send and now leaves out are kept, not removed, and listed in dropped; send them again or delete the record. When a record disagrees with a fact from a stronger source, the stronger fact keeps answering and a knowledge.fact.conflict event is sent to your webhooks.

Every valid record is applied and reported on its own, in order, so one bad record never blocks the rest. The request fails with 400 only when the batch itself is wrong (no records, or more than 500). written, unchanged and failed count the outcomes. A workspace may push 100,000 records an hour; past that the request is refused with 429 and Retry-After, and the whole batch is rejected.

Changing knowledge needs the knowledge:write scope, and the caller must act as an admin of the organization. Anyone else gets 403. A test key reads and changes the sandbox's knowledge and a live key the live knowledge; they never mix. The operation is naturally idempotent, so retrying a batch after a timeout is safe; still send an Idempotency-Key.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
sourcepathstringYesYour name for the system the records come from: 1 to 60 characters of a-z, 0-9, - and _.
Idempotency-KeyheaderstringNoMakes a POST safe to repeat: the same key returns the first result for 24 hours. The same key with a different body is refused with `422 idempotency_key_reused`; while the first request still runs, `409 idempotency_in_progress`.

PUT/v1/knowledge/sources/{source}/records/{external_id}

Write one record

Creates or replaces one record from one of your own systems. The record's id in your system is the external_id in the path; any external_id in the body is replaced by it. The body is a record: kind (an ontology type such as product or branch, up to 60 characters), name (up to 300), optional aliases (up to 50, for Nepali spellings, short names and model numbers), facts (up to 200, each a sentence of up to 4,000 characters with a relation), links to other records of the same source, and updated_at, the time your system last changed it.

The same rules as the batch apply: identical content is unchanged, an older updated_at is stale and never replaces a newer record, and a record with deleted: true retires its facts. A fact's audience is public, customers or staff, and valid_to must be after valid_from. Relations a record used to send and leaves out now are kept and listed in dropped. Use the batch for more than a few records.

An invalid record is a 400 whose message says what is wrong. The answer reports what happened as a result of written, unchanged, stale or deleted. Writing counts against the hourly push budget of 100,000 records.

Changing knowledge needs the knowledge:write scope, and the caller must act as an admin of the organization. Anyone else gets 403. A test key reads and changes the sandbox's knowledge and a live key the live knowledge; they never mix. Writing the same record again is a no-op, so retries are safe.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
sourcepathstringYesYour name for the system the records come from: 1 to 60 characters of a-z, 0-9, - and _.
external_idpathstringYesThe record's id in your system, 1 to 200 characters. Percent-encode it if it contains `/`.

DELETE/v1/knowledge/sources/{source}/records/{external_id}

Delete one record

Retires a record: its facts stop answering, and what they replaced answers again. The history is kept. Use it when the thing no longer exists in your system; to take back everything a bad sync wrote, use rollback instead.

The server answers 204 No Content on success. A record that was never pushed, or is already deleted, is a 404, so a retry after success sees a 404 and may treat it as done. Pushing the record again later brings it back.

Changing knowledge needs the knowledge:write scope, and the caller must act as an admin of the organization. Anyone else gets 403. A test key reads and changes the sandbox's knowledge and a live key the live knowledge; they never mix.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
sourcepathstringYesYour name for the system the records come from: 1 to 60 characters of a-z, 0-9, - and _.
external_idpathstringYesThe record's id in your system, 1 to 200 characters. Percent-encode it if it contains `/`.

POST/v1/knowledge/sources/{source}/rollback

Roll a pushed source back

Undoes a bad sync of a source you push records into. Send since, an RFC 3339 time. Every fact this source wrote at or after that time is closed, and the facts those replaced answer again. The answer is {closed, restored}.

Nothing is erased: the closed facts stay in the history. If your system sends the same bad records again they will be written again, so stop it first. A since in the future closes nothing. For a website AirFone reads itself, use the rollback under connections.

Changing knowledge needs the knowledge:write scope, and the caller must act as an admin of the organization. Anyone else gets 403. A test key reads and changes the sandbox's knowledge and a live key the live knowledge; they never mix. Rolling back to the same time twice does nothing the second time, so a retry is safe. Send an Idempotency-Key so a retried request does not repeat the action.

Scope knowledge:write. Accepts: API key or personal access token. Open in the API reference

ParameterInTypeRequiredDescription
sourcepathstringYesYour name for the system the records come from: 1 to 60 characters of a-z, 0-9, - and _.
Idempotency-KeyheaderstringNoMakes a POST safe to repeat: the same key returns the first result for 24 hours. The same key with a different body is refused with `422 idempotency_key_reused`; while the first request still runs, `409 idempotency_in_progress`.