Palbase ai · API
/ai/chats/{chat_id}/messagesWrite to a chat
A message for the agent: a turn of its own when none runs; while one does, at its next step (next) or cutting the step it is in (now). The same client_id again is the same message. A user sends user_messages_per_minute a minute — and so does the server writing as them (429 too_many_messages); past the history the project keeps a message is refused (409 history_full). It carries pictures of the project's storage the model is shown (images) and, in a chat that works in a workspace, files put in it before the agent reads the message (files), each copied for the chat. Its turn is its writer's work: a member's own message makes the turn theirs, and its cost is recorded as theirs; the server's message, as itself or written as a member (as), is the project's alone and no person's. A member whose AI is off in the project (blocked, or a limit of 0: PUT /ai/users/{user_id}/quota) is refused (403 user_ai_blocked, "AI is off for you in this project"), as are their messages to a subagent and the voices they start.
Called by a signed-in user of your app, with their token and the publishable key; or your server, with the project's secret key.
Path
chat_idstring · requiredThe chat's id.Request body
asstring · optionalThe member the server writes as (the server's alone: a user sending it is answered 400; one who is not a member of the chat, 403 not_a_member): the message is theirs, and counts toward their messages a minute (429 too_many_messages, as theirs would).budgetobject · optionalWhat the turn a message starts may cost at most, its subagents' spend counted, their model calls and their web searches (the server's alone): past it the engine stops the turn. A message delivered into a turn already running takes that turn's.client_idstring · requiredThe writer's own id for it: sent again — a retry, a second tab — it is the same message, delivered once.contextstring · optionalWhat the model reads with the message and no member does (the server's alone: a user sending it is answered 400; 64 KiB at most): a document the agent needs, how to open a file the message names. The agent is told it as the project's own words, apart from the writer's; the chat's stream and its list never show it.delivery"next" | "now" · optionalWhile the agent works on a turn: next gives it the message at its next step (the default), now cuts the step it is in. When no turn runs, a message starts one.filesobject[] · optionalFiles of the project's storage given to the agent with the message (8 at most, 50 MB each at most), by what their bytes are: a PDF whole, each page as its text and as a picture; a picture (png, jpeg, webp or gif, 5 MiB at most) shown, while the message shows fewer than 4; a Word, Excel or PowerPoint file (.docx, .xlsx, .pptx) or a text file as its text, drawn out by the platform (400,000 bytes of it at most). In a chat that works in a workspace each is also put in it before the agent reads the message, at .palbase/attachments/<message id>/<filename>, and the agent is told where. A chat that works in no workspace refuses a file its agent is given nothing of (415, 413 or 422 unreadable_attachment). Copied for the chat, and who may attach which, as images; an object the message names twice — a picture of it and a file of it too — is read once.imagesobject[] · optionalPictures of the project's storage the model is shown with the message (4 at most, as many as the model is shown at once; png, jpeg, webp or gif by their bytes, whatever they are labelled — another is 415 unsupported_image; 5 MiB each at most). Each is copied for the chat as the message is written: what it carried is what the agent reads, whatever becomes of the file, and the copy goes with the chat. The server attaches any file of its storage, writing as a member or not: its decision. A member with their own session attaches a public bucket's files alone — a private bucket's file, their own (owner_id) too, is the server's to attach. Any other is not found (404 attachment_not_found), as one that is not there is. Past the bounds: 413 attachment_too_large; changed while it was attached: 409 attachment_changed.metadataobject · optionalIts writer's own labels for the message (16 at most, snake_case keys, values of 512 bytes at most) — what an app draws it by: the files it names, the kind of row it is, the model its writer chose. Kept with it, shown with it in the chat's stream and its list, and given to the backend that defines the agent of the turn it opens (the agent context's message). Sent again with the same client_id, the first message's stand.textstring · requiredThe message's words (64 KiB at most): empty only when it carries images or files, which then say it.curl -X POST "https://<your-ref>.palbase.studio/ai/chats/<chat_id>/messages" \
-H "apikey: $PALBASE_SECRET_KEY" \
-H "content-type: application/json" \
-d '{"client_id":"string","text":"string"}'Responses
200The message, sent before
202The message, given to the agent
400The request is malformed, or names what this module does not offer (the error names which)
401No valid credential
403A publishable key or a user's session: everything here is the project's server's, called with the secret key
404No such response, job or provider in this project
409The response's state refuses it
413The body is larger than the route takes
429The project's request rate, or the provider's for its connection, is used up — or the project holds as much as it may at once: 32 open streams at one of the module's servers (too_many_streams), 2 pictures being made (too_many_images), 512 MiB of pictures kept here for their day (image_storage_full), or the service — or the project's share of it — holds as much of its requests at once as it takes: their bodies, an embedding request's vectors, the pictures being made (busy). Retry-After says when to try again
503The model service or the database did not answer; retry shortly
defaultAn error: the envelope names it (`error`) and explains it (`error_description`).
Operation SendChatMessage of ai's contract.