Skip to main content

API reference

The Ask AI API answers a question from your site's content and returns the answer with its sources. It has one endpoint, POST https://api.sorchy.com/v1/ask, called from your own server. A Postman collection is available under Tools > API > Documentation; put your key in its apiKey variable to try it.

Keys

Create keys under Tools > API > Setup, up to 5 per project, each named for where it is used. Send the key in the Authorization header. Keep it on your server, for example in an environment variable; never put it in browser code, a mobile app bundle or a public repository.

POST https://api.sorchy.com/v1/ask
Authorization: Bearer sk_live_...
Content-Type: application/json

Request

FieldTypeRequiredDescription
questionstringYesThe question, up to 1,000 characters. The project's personal data masking applies.
conversation_idstringNoThe conversation_id of an earlier answer, to continue that conversation with its earlier questions as context.
lang"tr" or "en"NoThe language of the user's page or app. Answers normally follow the question's language and the project's answer language setting.
streambooleanNotrue returns the answer in pieces as NDJSON. Default false.

A minimal request body is {"question": "When do applications open?"}. Ready-made requests for cURL, JavaScript and Python are in the panel under Tools > API > Documentation.

Response

answer is Markdown. Marks such as [1] and [3] point to the sources with the same n; sources holds only the sources the answer cites.

{
  "conversation_id": "5f0c…",
  "message_id": "a94b…",
  "answer": "… [1] … [3]",
  "sources": [
    { "n": 1, "title": "…", "url": "https://…" },
    { "n": 3, "title": "…", "url": "https://…" }
  ]
}

Streaming

With "stream": true in the body, the answer comes as NDJSON, one JSON event per line. The sources event lists every page found, so you can link [n] marks while the text arrives; done lists only the cited sources. On an error, an error event arrives and the stream ends.

{"type": "conversation", "conversation_id": "5f0c…", "message_id": "a94b…"}
{"type": "sources", "sources": [{"n": 1, "title": "…", "url": "…"}]}
{"type": "token", "text": "…"}
{"type": "token", "text": "…"}
{"type": "done", "sources": [{"n": 1, "title": "…", "url": "…"}]}

Follow-up questions

Send the conversation_id of an answer with the next request, and the new question is read in the context of the earlier ones, so “And the fee?” works. API conversations appear under Conversations on the API channel.

Errors

Errors return an HTTP status and a body of the form {"error": {"code", "message"}}. Act on code; message may change.

HTTPCodeMeaning
400question_requiredThe question is empty.
401missing_api_keyNo Authorization header, or not in the form Bearer sk_live_....
401invalid_api_keyThe key is not valid or has been revoked.
403api_not_in_packageThe project's package does not include the API.
403api_offThe API is turned off in Tools > API > Setup.
403assistant_pausedThe package's days or questions have run out; answers are paused.
409index_emptyThe project has no content to answer from yet.
422invalid_requestThe request body is not valid; details names the wrong field.
429rate_limitedToo many questions for this key; wait the seconds in the Retry-After header.
502answer_failedThe answer could not be made; try again shortly.

Limits

  • Up to 60 questions per minute per key.

  • Each question counts toward the project's monthly questions, like questions on your site.

  • Server-to-server only: requests from browsers (CORS) are refused.

  • An answer can take from a few seconds to a minute; set your client timeout to at least 120 seconds.