Palbase ai · API
/ai/responsesAsk a model
Admits a response: an answer to the input, as text or — with a schema — as a JSON document of that shape, validated before it is returned. With stream: true the answer is the response's live view (text/event-stream). With background: true it answers at once and the response's end is the event ai.response.completed (or ai.response.failed). Otherwise it answers at once with the response queued; read it by its id. What the agent is given — its instructions, the conversation, the schema and the tools together — is at most 1 MiB as JSON, what the model service reads (413 request_too_large).
Called by your server, with the project's secret key.
Headers
Idempotency-Keystring · requiredMakes the request safe to send again (at most 255 characters): the same key with the same request is the same response or job, so a retry never asks — or pays — twice.Request body
agentstring · optionalAn agent of the project's — its name (the version published), or name@N (version N): its instructions, model, tools and output shape the answer. A field this request names replaces the agent's for this answer alone; the agent is not changed.backgroundboolean · optionalAnswer at once; the response's end is the event ai.response.completed or ai.response.failed.imagesobject[] · optionalPictures the question is about, shown to the model with it (4 at most).inputstring · optionalThe question (2 MB at most). Give this, or messages.instructionsstring · optionalHow the model should answer (256 KB at most).max_tool_callsinteger · optionalHow many tool calls the answer makes at most (10000: the engine's own bound): past it the model is told it has no tools left and answers.messagesobject[] · optionalThe conversation so far instead of one question (500 turns at most); its last turn is the user's.metadataobject · optionalThe caller's own labels (16 at most, snake_case keys): returned with the response and its event.modelstring · optionalA model's name, as GET /ai/models says it (gpt-6-luna), or left out for the project's default. A deprecated model still runs; the catalogue says what to name instead.schemaobject · optionalA JSON Schema the answer must be a document of. Its keywords are the provider's strict subset: type, properties, required, additionalProperties, items, enum, description, title, minimum, maximum, minLength, maxLength, minItems, maxItems — no $ref, at most 12 levels and 512 properties; every property required (a nullable one may be null). One outside the subset is refused, naming where it is.schema_namestring · optionalThe schema's name, as the model is told it (letters, digits, _ and -; default answer).streamboolean · optionalAnswer with the response's live view (text/event-stream).toolsobject[] · optionalWhat the model may call to answer: the project's backend's functions, its HTTPS tools and MCP servers (an app's own tools are a chat's).curl -X POST "https://<your-ref>.palbase.studio/ai/responses" \
-H "apikey: $PALBASE_SECRET_KEY" \
-H "content-type: application/json" \
-d '{"agent":"string","background":false,"images":[{"bucket":"string","data":"string","media_type":"string","path":"string","url":"https://example.com"}],"input":"string","instructions":"string","max_tool_calls":1,"messages":[{"content":"string","role":"user"}],"metadata":{},"model":"string","schema":{},"schema_name":"string","stream":false,"tools":[{"name":"string","source":"backend"}]}'Responses
200Server-sent events, in this order: `response` (the Response as admitted), `delta` ({offset, text}: a fragment of the answer at its byte offset), `reset` ({offset}: discard what you hold past the offset — a model call was made again), `terminal` (the Response at its end), and `: heartbeat` comments. A stream cut before its terminal is followed again with GET /ai/responses/{response_id}/live?offset=<bytes held>: the response itself never stopped.
202The response, admitted
400The request is malformed, or names what this module does not offer (the error names which)
401No valid credential
402Palbase's models do not serve the project now and it has not connected its own key for this model's provider (PUT /ai/providers/{provider}): its monthly AI budget is spent (ai_budget_reached), its month's free dollar is spent and it has no paid rights to pay past it (ai_payment_required), or they do not serve it (provider_key_required). GET /ai/spend says which.
403A publishable key or a user's session: everything here is the project's server's, called with the secret key
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 CreateResponse of ai's contract.