Docs / Messages and tasks

Guides

Messages and tasks

How a message becomes work, how to wait for Ragnar's reply, and how to answer its questions.

You talk to Ragnar with messages, as in the app. Every message you send gets a task. The task says how the work on that message goes, so your program can wait for it without reading text.

Send a message

Terminal
curl -X POST "$RAGNAR_API/v1/chats/<chat_id>/messages" \
  -H "Authorization: Bearer $RAGNAR_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{"text": "Make the bracket 5 mm thicker.", "effort": "medium"}'

textstring, 1 to 100,000 characters
What you want, in plain words, without outer spaces. Include sizes and units. With one short reference for each file, the message must still fit in 100,000 characters (400 PROMPT_TOO_LARGE).
filesoptional array of `{id}`
Up to 64 different files that are in the folder of the chat's project now. A message can name a file name only once, whatever its case.
reply_tooptional array with one id
The question this message answers. Leave it out and Ragnar still takes your message as the answer while its question waits for you in this chat, unless the message is /export.
effortoptional string
low (Quick), medium (Balanced, the default), high (Thorough) or xhigh (Deep). In a personal project, high and xhigh need Pro on your own account; a workspace project allows every effort. An answer keeps its build's effort.
ask_clarifying_questionsoptional boolean
Defaults to false: Ragnar never stops to ask. With true, Ragnar can ask one set of up to three questions before it starts the CAD work. Your question setting in the app does not apply to the API.

Ragnar decides what a message is, in this order:

  1. With reply_to, the message answers that question. /export with reply_to gets 400 INVALID_REQUEST.
  2. /export is always an export, also while a question waits for you.
  3. Without reply_to, while a question waits for you in this chat, the message answers it, also when it starts with /plan. Ragnar fills in reply_to.
  4. Otherwise the message is a new request, or /plan. See slash commands.

One build at a time

A project's main design builds one thing at a time, across all its chats, the app's chats included. While a build is pending, working or paused, or a message is still starting, a new request gets 409 PROJECT_BUSY, and the error message says which chat and why. You cannot add to a build that is running.

  • A pending or working build ends by itself. Wait for it, then send the request again.
  • A paused build waits for someone. When it asked you a question, answer it. Otherwise continue or stop it in Ragnar.

An answer to a question asked of you, and /export, skip this check. They can still be refused for other reasons: for an answer, the credit limit of the key that started the build; for /export, the hourly limit.

Task statuses

Read a task with GET /v1/tasks/{task_id} about every 5 seconds:

idstring
The task's id. Take it from a message's task_id.
message_idstring
The message the task follows.
statusstring
pending, working, paused, answered, failed or cancelled.
reasonstring or null
Why, when the task is paused or failed. Otherwise null.
pendingkeep polling
Nobody has started on the message yet, or its answer waits for the last build to finish saving. Ragnar's question stays pending until someone answers it.
workingkeep polling
Ragnar is working on an answer, or delivering the files of its work.
pausedact in Ragnar
The work stopped but can go on. reason says why. Continue it in Ragnar; the API cannot continue it.
answeredread the reply
The message has its answer. Read the messages after your message.
failedstop polling
The work did not succeed. reason says why. Try again in Ragnar can start it again.
cancelledstop polling
Someone stopped the work in Ragnar, or the question is no longer asked.

When a task is paused or failed, reason says why:

out_of_creditspaused
Your account or the workspace has no credits left. Add credits, then continue the build in Ragnar.
api_key_credit_limit_reachedpaused or failed
The key's monthly credit limit ran out before the credits did. When paused, continue the build in Ragnar after the reset or with a higher limit. When failed, nothing started: send the message again then.
paused_by_userpaused
Someone paused the build in Ragnar.
pausedpaused
The build paused for another reason. Continue it in Ragnar.
resume_refusedpaused
An answer came, but Ragnar could not continue the build. The reason can also be the refusal's own error code, in lower case, such as rate_limited. Continue the build in Ragnar.
build_failedfailed
The build failed. When Ragnar wrote a note about it, the note names your message in reply_to.
not_startedfailed
Ragnar answered but started nothing: for example, another chat started a build first, or /export named no format or found no saved model. The reply says why.
export_failedfailed
/export could not make the file, for example when the design has nothing to draw.
no_responsefailed
Ragnar never answered the message.

Accept status and reason values you do not know: Ragnar can add new ones.

Read the reply

When a task is answered, read the messages after the message you sent:

Terminal
curl "$RAGNAR_API/v1/chats/<chat_id>/messages?after=<message_id>" \
  -H "Authorization: Bearer $RAGNAR_API_KEY"

Pass the message you sent as after, not the newest message you have. A reply that starts no build, such as the reply to /export, is listed right after its message, even when its text was written after later messages.

Ragnar's messages after yours hold the result: its words, and in files, the files its work wrote. Ragnar can write more than one message, and its notes in the chat, such as the one when someone stops a build, have no task_id. A Ragnar message with a task_id is a question its build asked. It is yours when its reply_to holds your message. It keeps its task_id after it is answered or cancelled, so read its task: it waits only while the task is pending.

A build's files fill in as the work delivers them, and a reply can be listed before they are all there. Read the reply again after the task is answered to get every file. A build is answered even when an export you asked for could not be made, so check files for each file you need.

When a build fails, the task is failed. Ragnar's note about it, when it writes one, names your message in reply_to.

Questions

Ragnar builds without asking by default. Send "ask_clarifying_questions": true to let it ask one set of up to three questions before it starts the CAD work:

  1. Your message's task is answered by the question.
  2. The question is a message from Ragnar with its own task_id. Its text lists each question with its options, then what Ragnar will assume. Its task stays pending until you answer.
  3. Answer every question in one message. You can name the question in reply_to, or leave it out: while the question waits for you, your next message in the chat is the answer.
  4. Follow your answer's task. The build goes on from there, with the effort it started with.

Only the person who was asked can answer, through the API or in the app. A question the build no longer waits for is cancelled.

Slash commands

A message that starts with a slash command is that command, as in the app, unless it answers a question as above. A command counts only at the start of the text, in any case.

  • /export <format> exports the saved design as a file. See exports.
  • /plan <what you want> asks Ragnar for a plan before anything is built. Ragnar writes the plan in the project and replies with what it needs you to decide. To build it, send a message such as Go ahead. Read the plan itself in Ragnar.

Any other text that starts with / is an ordinary message.

Things to know

  • The API cannot continue or stop work. A paused build continues in Ragnar.
  • Try again in the app can move a failed task back to working, or start a fresh build that your message's task does not follow.
  • A message someone queued in the app is listed at the time it was written, not the time it was sent.