Skip to content

Generate a file, or say how to reshape one

POST
/ai/source
curl --request POST \
--url https://api.sloose.com/ai/source \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "question": "example", "grid": [ [ "example" ] ], "totalRows": 1, "delimiter": ",", "quote": "\"", "collapse": true, "rowFilter": "example", "raggedRows": [ { "at": 1, "cells": [ "example" ] } ], "raggedCount": 1, "want": "filter", "enabledModules": [ "example" ] }'

Help with the source file before any of it is mapped: invent one shaped for the modules this import is for, or read the one you have and say what is wrong with it.

A reshape comes back as a recipe, not as data. Your file has as many rows as it has and the model is shown twelve, so anything it handed back would be a rewrite of the twelve. Instead it returns steps — a closed set of named operations (use_header_row, set_header, drop_rows, rename_column, drop_column, fill_down) which you apply to every row yourself. @sloose/source-csv exports reshapeSource to do exactly that; willDo is the same list in plain words, one line per step.

The file’s shape, never its values. Splitting a name into two columns or stripping a currency symbol are mapping rules — one expression on the Map step does them per field without rewriting every row — so there is no operation for them here, and asked for one the assistant says so.

Every step is dry-run before you see it, one at a time and cumulatively against the records the model was shown, so a rename can feed the fill-down after it. A step that reports a problem is dropped and named in notes.

Two answers are not steps. parse says the separator or text qualifier in use is wrong and the file should be re-read; rowFilter is an expression that is TRUE for the rows to keep, compiled and run in the sandbox against your own rows before it is offered.

Send grid as the file parsed into raw records, header included and nothing interpreted, plus raggedRows — the records whose field count differs from the header’s, at their real positions. A file that will not parse is broken on one line and that line is never in the first twelve, so without those the answer is about the healthy part of the file. Omit grid entirely to ask for a file to be generated.

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. An org set to deny is refused with SAMPLES_DENIED when a grid is sent, and can still generate.

Media typeapplication/json
object
question
required
string
>= 1 characters <= 2000 characters
grid
Array<Array<string>>
<= 50 items
totalRows
integer
delimiter
string
Allowed values: , ; |
quote
string
Allowed values: " '
collapse
boolean
rowFilter
string
<= 2000 characters
raggedRows
Array<object>
<= 10 items
object
at
required
integer
> 0
cells
required
Array<string>
<= 200 items
raggedCount
integer
want
string
Allowed values: filter
enabledModules
Array<string>

What it made of the file. Nothing has been changed: the steps are yours to apply.

Media typeapplication/json

An answer in words, plus either a recipe (steps and willDo) or a generated file.

object
requestId
required

This call’s id. It is also the ledger’s idempotency key.

string
credits
required

Credits settled for this call.

number
usage
required

Token counts, including cache reads and writes.

object
key
additional properties
model
required

The model that answered.

string
key
additional properties
Examplegenerated
{
"requestId": "example",
"credits": 1,
"usage": {
"additionalProperty": "example"
},
"model": "example"
}

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"
}
}

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"
}