Skip to content

Chat about the import (server-sent events)

POST
/ai/chat
curl --request POST \
--url https://api.sloose.com/ai/chat \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "sessionId": "example", "message": "example", "columns": [ "example" ], "sampleRows": [ { "additionalProperty": "example" } ], "enabledModules": [ "example" ] }'

A conversational turn with tools: read the schema, propose a mapping, test an expression, explain a problem.

The response is a text/event-stream, not JSON. Events arrive in this order:

Event Meaning
session { sessionId, requestId } — send sessionId back to continue this conversation.
(tool events) One per tool call and result, as the turn proceeds.
done { sessionId, requestId, credits, usage, model, turns } — the turn finished and the meter is settled.
error { code, error } — the turn failed; the reservation is released.

A turn that fails part-way still emits error rather than closing silently, so a client never has to guess. Fields the org has annotated as personal data are masked before any sample leaves the server, and an org whose AI sample policy is deny sends no rows at all.

Media typeapplication/json
object
sessionId

Continue an existing chat. Omit to start one.

string
message
required
string
>= 1 characters <= 8000 characters
columns
Array<string>
<= 500 items
sampleRows
Array<object>

One source row: column name → cell value, always as a string.

object
key
additional properties
string
enabledModules
Array<string>
Examplegenerated
{
"sessionId": "example",
"message": "example",
"columns": [
"example"
],
"sampleRows": [
{
"additionalProperty": "example"
}
],
"enabledModules": [
"example"
]
}

The event stream. See the table above for the event sequence.

Media typetext/event-stream

Server-sent events.

string

The body did not match the schema (BAD_INPUT, with issues), or a named module or field does not exist.

Media typeapplication/json
object
error
required
string
code
required
string
key
additional properties
Examplegenerated
{
"error": "example",
"code": "example"
}

No bearer, or one that is expired, revoked or no longer resolves to a member.

Media typeapplication/json

The error envelope every non-2xx answer uses.

object
error
required

Human-readable explanation.

string
code

Machine-readable reason. Absent on a few legacy 400s.

string
key
additional properties
Examplegenerated
{
"error": "example",
"code": "example"
}

Not enough AI credits, or the org is suspended. balance shows what is left.

Media typeapplication/json
object
error
required
string
code
required
string
balance
required

AI credits. Included credits reset each period; purchased ones do not.

object
included
required
number
purchased
required
number
reserved
required
number
available
required

Included + purchased − reserved

number
periodStart
required
string
periodEnd
required
string
key
additional properties
Examplegenerated
{
"error": "example",
"code": "example",
"balance": {
"included": 1,
"purchased": 1,
"reserved": 1,
"available": 1,
"periodStart": "example",
"periodEnd": "example"
}
}

That chat session belongs to somebody else.

Media typeapplication/json
object
error
required
string
code
required
string
Allowed values: SESSION_FORBIDDEN
key
additional properties
Example
{
"code": "SESSION_FORBIDDEN"
}

No such org.

Media typeapplication/json
object
error
required
string
code
required
string
Allowed values: ORG_NOT_FOUND
key
additional properties
Example
{
"code": "ORG_NOT_FOUND"
}

The org has no module registry yet — run discovery and enable some modules first.

Media typeapplication/json
object
error
required
string
code
required
string
Allowed values: ORG_NOT_CONFIGURED
key
additional properties
Example
{
"code": "ORG_NOT_CONFIGURED"
}

The model declined. category says why.

Media typeapplication/json
object
error
required
string
code
required
string
Allowed values: AI_REFUSED
category
required
string
key
additional properties
Example
{
"code": "AI_REFUSED"
}

The model’s answer could not be used.

Media typeapplication/json
object
error
required
string
code
required
string
Allowed values: AI_BAD_OUTPUT
key
additional properties
Example
{
"code": "AI_BAD_OUTPUT"
}

AI is not configured on this deployment. Unconfigured paths say so rather than failing.

Media typeapplication/json
object
error
required
string
code
required
string
Allowed values: AI_NOT_CONFIGURED
key
additional properties
Example
{
"code": "AI_NOT_CONFIGURED"
}