← All features

Beya API

The Beya API lets your software ask Beya a question about a business, the same way you would in Beya's chat. Beya reads the data the business has connected, such as its Shopify store or Klaviyo account, and returns the same answer its chat gives: the text, and each table in full.

Use a read to get an answer. To ask Beya to change something, use a turn and a key with write access. Create a key in Beya under Settings, API keys. Each read uses one question from your plan.

Overview

Send requests to https://agent-api.usebeya.com. Requests and responses are JSON. Call the API from your server: do not use your client secret in a browser or a mobile app.

MethodPathDescription
POST /v1/oauth/token Get an access token for one business.
GET /v1/capabilities Get what a token can do and the sources a read can draw on.
POST /v1/reads Ask a question, or answer one Beya asked back.
GET /v1/reads/{readId} Get the status or result of a read.
POST /v1/turns Ask a question, request a change, or reply to a pending turn.
GET /v1/turns/{turnId} Get the status or result of a turn.

Quick start

These three requests get a token, ask a question and get the answer.

1. Get a token

Use the client ID and secret of a key from Settings. A token lasts 10 minutes and can only be used for your own business.

Request
curl "https://agent-api.usebeya.com/v1/oauth/token" \
  -u "$BEYA_CLIENT_ID:$BEYA_CLIENT_SECRET" \
  -d grant_type=client_credentials
Response 200
{
  "access_token": "beya_at1.eyJ2IjoxLCJjaWQiOiJ5b3VyLWNsaWVudCJ9.Qm9…",
  "token_type": "Bearer",
  "expires_in": 600,
  "scope": "capabilities:read reads:figures"
}

2. Ask a question

Each read needs an Idempotency-Key header that you choose. The wait parameter keeps the request open for up to 50 seconds while the read runs.

Request
curl "https://agent-api.usebeya.com/v1/reads?wait=50" \
  -H "Authorization: Bearer $BEYA_TOKEN" \
  -H "Idempotency-Key: top-products-2026-10" \
  -H "Content-Type: application/json" \
  -d '{
    "question": "What were my top 3 products by revenue last month?"
  }'

3. Get the answer

If the read finishes within the wait, the response is 200 with the result. If not, it is 202 with the read id, and you request the read again until it has finished.

Response 202
{
  "readId": "rd_3a7f0c2b9d4e1f6a8b5c0d2e7f1a4b6c9d3e5f70",
  "status": "running",
  "retryAfterMs": 2000
}
Request
curl "https://agent-api.usebeya.com/v1/reads/$READ_ID?wait=50" \
  -H "Authorization: Bearer $BEYA_TOKEN"
Response 200
{
  "readId": "rd_3a7f0c2b9d4e1f6a8b5c0d2e7f1a4b6c9d3e5f70",
  "status": "answered",
  "answer": {
    "text": "Your top 3 products by revenue in October were:\n\n| Product | Revenue |\n| --- | --- |\n| Linen Shirt | £8,420.00 |\n| Wool Scarf | £6,115.50 |\n| Canvas Tote | £4,980.00 |",
    "tables": [
      {
        "title": "Top products by revenue, October 2026",
        "headers": ["Product", "Revenue"],
        "rows": [["Linen Shirt", 8420], ["Wool Scarf", 6115.5], ["Canvas Tote", 4980]],
        "rowCount": 3,
        "truncated": false
      }
    ]
  }
}

The values in these examples are made up.

Authentication

POST /v1/oauth/token

This endpoint uses the OAuth 2.0 client credentials grant. A key's client ID and secret are the client_id and client_secret. Send the fields as a form or as JSON. Put the token it returns in the Authorization header of every other request, as Bearer followed by the token.

grant_type string required
Must be client_credentials.
client_id string
Your key's client ID, which starts with bk_. Send it in the body with client_secret, or send both with HTTP Basic authentication.
client_secret string
Your key's client secret, which starts with beya_sk_. Keep it on your server.
business_id string
Leave it out when you use a key made in Beya: the token is for your own business. A client set up for several businesses sends the one the token is for.
scope string
The scopes to include, separated by spaces. If you leave it out, the token gets all of your key's scopes.

Scopes

A key made in Beya has capabilities:read and reads:figures. A token can have some or all of its key's scopes.

ScopeAllows
capabilities:read Call GET /v1/capabilities.
reads:figures Create and get read-only questions.
reads:rows Create and get the same read-only answers as reads:figures.
turns:write Create and get turns that can read data and make changes under the owner’s permission settings.

Errors from this endpoint

These errors use the standard OAuth format, for example { "error": "invalid_client" }, so OAuth client libraries can handle them.

ErrorStatusMeaning
invalid_request 400 A field is missing or has the wrong format.
unsupported_grant_type 400 grant_type is not client_credentials.
invalid_scope 400 Your client does not have one of the requested scopes.
invalid_client 401 The client ID or secret is wrong, or the key was revoked.
access_denied 403 Your key cannot act for that business, or the account cannot use Beya.
temporarily_unavailable 503 Tokens cannot be issued right now. Try again later.

Capabilities

GET /v1/capabilities Scope: capabilities:read

Returns what this token can do and the sources the business has connected, which a read draws on the same way Beya's chat does.

Request
curl "https://agent-api.usebeya.com/v1/capabilities" \
  -H "Authorization: Bearer $BEYA_TOKEN"
Response 200
{
  "version": 2,
  "client": { "id": "bk_5f2a9c0e7d1b4a6c8e3f0a2b", "name": "Weekly report script" },
  "businessId": "b7c1e2a0-…",
  "scopes": ["capabilities:read", "reads:figures"],
  "reads": true,
  "answers": "web-chat",
  "sources": ["klaviyo", "shopify"],
  "maxConcurrentReads": 2,
  "readOnly": true,
  "environment": "production"
}

Create a read

POST /v1/reads Scope: reads:figures

The request body is JSON. Unknown fields are rejected with invalid_request.

question string required
Up to 8,000 characters of plain text. If Beya asks for more information, send your answer here with the original read ID in replyTo.
replyTo string
The id of a read whose status is needs_input. Send it with your answer in question, and Beya continues that read with the information you supplied.
skill string
One of Beya's shipped skills to use for this question, as / uses one in chat. evidence-packet reads the question twice, independently, and answers with the figures both reads agree on, those that differ and the tables behind them. A skill whose sources the business has not connected is refused with invalid_request, and so is one sent with replyTo.

Idempotency key

Every read needs an Idempotency-Key header of 8 to 128 characters, using letters, digits and _ . : -. If you send the same key with the same body, you get the stored result and no new read starts. If you send the same key with a different body, you get idempotency_conflict. To retry a failed read, use a new key.

Waiting for the result

The wait query parameter sets how long the request stays open, from 0 to 50 seconds. The default is 25. If the read has not finished by then, the response is 202 with a Retry-After header and the read id.

Get a read

GET /v1/reads/{readId} Scope: reads:figures

Returns 202 while the read is running and 200 with the result when it has finished. The wait parameter works as described above. Results are kept for 24 hours. A read id that does not exist, has expired or belongs to another client returns read_not_found.

Read results

A finished read has one of three statuses.

StatusMeaning
answered Beya answered. answer.text is the answer as its chat writes it, and answer.tables has each table in full.
needs_input Beya needs more information. Answer its clarification question with another read.
failed The read did not produce an answer. error.code gives the reason. The HTTP status is still 200, because this is the stored result for the key.

Response fields

readId string
The read's id, for GET /v1/reads/{readId}, and for replyTo when Beya asks something back.
status string
answered, needs_input or failed, or running while the read is in progress.
needs string
A read returns clarification when it needs more information.
answer object
For answered reads: text, the answer exactly as Beya's chat writes it (Markdown, with small tables inline), and tables, each table in full with its title, headers, rows, rowCount and truncated.
question object
For needs_input reads: what Beya asked, as text, the options it offers and allowFreeform, whether any other answer is accepted.
replyTo string
For a read that answered another: that read's id.
error object
For failed reads: a code and a message.

Failure codes

CodeMeaning
read_interrupted The read stopped before it finished. Try again with a new Idempotency-Key.
business_not_eligible The business stopped being eligible during the read. No results are returned.
read_failed The read could not be completed. Try again with a new Idempotency-Key.

Answering a question back

Sometimes Beya needs to know something before it can answer, such as which store or which period you mean. The read then ends with needs_input and Beya's question, the options it offers and whether any other answer is accepted.

Response 200
{
  "readId": "rd_8c1e5a0f2b7d4c9e6a3f1b0d5e8c2a7f4b9d6e10",
  "status": "needs_input",
  "needs": "clarification",
  "question": {
    "text": "Which store do you mean?",
    "options": ["UK store", "US store"],
    "allowFreeform": false
  }
}

To answer, create a new read with a new Idempotency-Key. Put your answer in question and the asking read's id in replyTo. Beya continues where it stopped. A read can be answered only while it is waiting; otherwise the request returns reply_not_open.

Request body
{
  "question": "UK store",
  "replyTo": "rd_8c1e5a0f2b7d4c9e6a3f1b0d5e8c2a7f4b9d6e10"
}

Create a turn

POST /v1/turns

Enable writes when you create a key in Settings, then request a token with turns:write. Send the same question and Idempotency-Key as for a read. The response includes turnId. A turn can answer with text and tables, request clarification, or make a change under the business owner’s permission settings.

Get a turn

GET /v1/turns/{turnId}

Use the same credential, business and turns:write scope. Poll the returned turnId while the response is 202. If a turn fails after asking for a change, check the result in the connected app before starting another turn.

Approving a change

When the owner’s permission settings require confirmation, a turn returns needs_input with needs set to approval, the exact change in question.text, and the replies that answer it in question.options.

Response 200
{
  "turnId": "tr_5d2b8e1a0c7f4b3e9a6d2c1f0e8b7a5d4c3e2f10",
  "status": "needs_input",
  "needs": "approval",
  "question": {
    "text": "Beya prepared this change. Nothing has been submitted.\n\nAccount: \"acme-klaviyo\"\nApp: \"klaviyo\"\n• \"Change\": \"Rename list VIP to VIP winback\"\n\nReply with YES to make this change, or NO to cancel it. It can be approved for the next 15 minutes.",
    "options": ["YES", "NO"],
    "allowFreeform": false
  }
}

To approve the change, post to /v1/turns with a new Idempotency-Key, YES in question and the asking turn’s turnId in replyTo. A change that sends a message or deletes something asks for an exact phrase instead, such as SEND NOW or DELETE, and only that phrase approves it. NO cancels the change, and so does any other answer. The reply's answer says what happened. A change can be approved for 15 minutes after it was prepared.

Request body
{
  "question": "YES",
  "replyTo": "tr_5d2b8e1a0c7f4b3e9a6d2c1f0e8b7a5d4c3e2f10"
}

A key approves changes for its authorized business with the turns:write scope. Show the change to the person responsible before you send YES. A reply that approves or cancels a change uses no question from your plan. If the business set Beya to make changes without asking, a turn can make the change at once, as the chat would, and its answer says what was done.

Same answer as chat

A read is answered the same way Beya's chat answers the same question. It uses the same connected data, the business's memories and its own chat instructions, and the answer has the same wording and tables. Nothing is added to your question and nothing is removed from the answer, so a read can include the same details the chat shows you, such as customers' names and orders.

What is different

  • A read can retrieve data and ask for clarification. Only a write-enabled turn can prepare or apply a change.
  • Each read is a single question. Beya does not see earlier reads, except the read a reply answers.
  • Files Beya creates in a write-enabled turn, such as a CSV export, can be downloaded in Beya but not through the API yet.

Errors

Other errors return an HTTP status and a body in the format below. Each code always has the same message, and messages do not include text from connected tools. Use code to handle errors.

Response 400
{
  "error": {
    "code": "invalid_request",
    "message": "The request is not valid.",
    "field": "question"
  }
}
CodeStatusMeaning
invalid_request 400 The request is not valid. field names the field with the problem.
unauthorized 401 The access token is missing, expired or not valid, or its key was revoked.
plan_required 402 The business needs a paid plan or an active trial to use the API.
forbidden_scope 403 The token does not have the scope this request needs.
business_not_eligible 403 The account can no longer use Beya.
read_not_found 404 There is no request with that ID on this route for this client and business.
idempotency_conflict 409 This Idempotency-Key was already used with a different request.
reply_not_open 409 The request named in replyTo cannot accept this reply.
rate_limited 429 The key reached its concurrent request limit. Reads and turns share this limit.
quota_exceeded 429 The business has used every question in its plan for this billing period.
reads_unavailable 503 The Agent API is temporarily unavailable.

Versioning

Integrations that previously used /v1/reads for changes must use a write-enabled key and /v1/turns. Check whether an earlier request applied the change before you start a new turn. Each route accepts replies and polling for its own ids.

Questions

Who can use the API?
Any Beya account on a paid plan or in its trial. Create a key in Beya under Settings, API keys. To give one application access to several businesses, email akbar@usebeya.com.
Is the answer the same as asking in Beya?
A read uses the same Agent and connected data. It can answer questions and return tables. Use a turn to request a change.
What does a read cost?
Each new read or turn uses one question from your plan. Repeating the same request with the same Idempotency-Key uses no extra question. A turn that approves or cancels a change also uses none.
Can a read change data in my store?
Reads are read-only for every key. To change store data, enable writes on a key and send the request to /v1/turns. The owner’s approval settings apply.
Does the API return customer data?
It returns what Beya's chat would show you for the same question, which can include customers' names, emails and orders. Keep your client secret and the answers on your server.
How long does a read take?
About as long as the same question takes in chat. A request waits up to 50 seconds for the result. If the read is still running after that, the response includes the read id so you can check again.
What happens if I send the same request twice?
If you send the same Idempotency-Key with the same body, you get the stored result and no new read starts. If you send the same key with a different body, the request is rejected.

Getting access

Sign in to Beya and open Settings, API keys. Name the key and create it, then copy its client ID and secret. The secret is shown once. You can have up to five keys, and revoking one stops it straight away.

Any account on a paid plan or in its trial can use the API. Each read uses one question from the plan, the same as a question in chat, and a repeated request with the same Idempotency-Key uses none.

To give one application access to several businesses, email akbar@usebeya.com.