REST API

Ai API

Generated from the Celerp 2.4.0 OpenAPI schema, 16 September 2026.

GET /ai/batch/{job_id}

Batch Status

Get batch job status and results.

Parameters

NameInRequiredTypeDescription
job_idpathyesstring--

Responses

StatusDescriptionBody
200Successful ResponseBatchJobOut
422Validation ErrorHTTPValidationError

Example

curl -X GET http://localhost:8000/ai/batch/:job_id \
  -H "Authorization: Bearer $TOKEN"

GET /ai/conversations

List Convs

List conversations, newest first, each with its count of open proposals.

Parameters

NameInRequiredTypeDescription
limitquery--integer--
offsetquery--integer--
include_protectedquery--boolean--

Responses

StatusDescriptionBody
200Successful Responsearray of ConversationOut
422Validation ErrorHTTPValidationError

Example

curl -X GET http://localhost:8000/ai/conversations \
  -H "Authorization: Bearer $TOKEN"

POST /ai/conversations

Create Conv

Create a new conversation.

Request body

FieldTypeRequiredDescription
titlestring, optional--Title

Responses

StatusDescriptionBody
201Successful ResponseConversationOut
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/conversations \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

GET /ai/conversations/{conversation_id}

Get Conv

Get a conversation with its messages and the reading jobs started from it.

Parameters

NameInRequiredTypeDescription
conversation_idpathyesstring--

Responses

StatusDescriptionBody
200Successful ResponseConversationDetail
422Validation ErrorHTTPValidationError

Example

curl -X GET http://localhost:8000/ai/conversations/:conversation_id \
  -H "Authorization: Bearer $TOKEN"

PATCH /ai/conversations/{conversation_id}

Rename Conv

Rename a conversation.

Parameters

NameInRequiredTypeDescription
conversation_idpathyesstring--

Request body

FieldTypeRequiredDescription
titlestringyesTitle

Responses

StatusDescriptionBody
200Successful ResponseConversationOut
422Validation ErrorHTTPValidationError

Example

curl -X PATCH http://localhost:8000/ai/conversations/:conversation_id \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

DELETE /ai/conversations/{conversation_id}

Delete Conv

Delete a conversation and all its messages.

Parameters

NameInRequiredTypeDescription
conversation_idpathyesstring--

Responses

StatusDescriptionBody
204Successful Response--
422Validation ErrorHTTPValidationError

Example

curl -X DELETE http://localhost:8000/ai/conversations/:conversation_id \
  -H "Authorization: Bearer $TOKEN"

POST /ai/conversations/{conversation_id}/confirm

Confirm Action

Execute one pending action the user has confirmed. No model turn resumes after a write; the user asks the next question. An action that is no longer pending, or whose module is not enabled, is 409.

Parameters

NameInRequiredTypeDescription
conversation_idpathyesstring--

Request body

FieldTypeRequiredDescription
message_idstringyesMessage Id
tool_call_idstringyesTool Call Id

Responses

StatusDescriptionBody
200Successful Responseobject
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/conversations/:conversation_id/confirm \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

POST /ai/conversations/{conversation_id}/confirm-all

Confirm All

Execute the pending actions on one message, in the order they were proposed. ``tool_call_ids`` narrows the run to a selection; without it every pending action runs. Each action is claimed and finalized on its own, so one failure never rolls back the others; the reply lists the outcome per action.

Parameters

NameInRequiredTypeDescription
conversation_idpathyesstring--

Request body

FieldTypeRequiredDescription
message_idstringyesMessage Id
tool_call_idsarray of string, optional--Tool Call Ids

Responses

StatusDescriptionBody
200Successful Responseobject
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/conversations/:conversation_id/confirm-all \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

POST /ai/conversations/{conversation_id}/dismiss

Dismiss Action

Persist dismissal of one proposal so it stays gone after reload.

Parameters

NameInRequiredTypeDescription
conversation_idpathyesstring--

Request body

FieldTypeRequiredDescription
message_idstringyesMessage Id
tool_call_idstringyesTool Call Id

Responses

StatusDescriptionBody
200Successful Responseobject
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/conversations/:conversation_id/dismiss \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

POST /ai/conversations/{conversation_id}/dismiss-all

Dismiss All

Persist dismissal of a selected proposal set under one message-row lock.

Parameters

NameInRequiredTypeDescription
conversation_idpathyesstring--

Request body

FieldTypeRequiredDescription
message_idstringyesMessage Id
tool_call_idsarray of stringyesTool Call Ids

Responses

StatusDescriptionBody
200Successful Responseobject
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/conversations/:conversation_id/dismiss-all \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

POST /ai/conversations/{conversation_id}/jobs/{job_id}/proposals

Propose From Job

Turn a finished reading job into bill proposals the user confirms. Vendors are matched to existing contacts and lines to items by exact name or SKU. When a vendor is missing and the user may create contacts, proposal order is vendor first, bill second; the bill stores a server-side result binding to the vendor action and resolves its returned id only when confirmation executes. Nothing is written until the user confirms a card. Calling again returns the same proposals.

Parameters

NameInRequiredTypeDescription
conversation_idpathyesstring--
job_idpathyesstring--

Responses

StatusDescriptionBody
200Successful Responseobject
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/conversations/:conversation_id/jobs/:job_id/proposals \
  -H "Authorization: Bearer $TOKEN"

POST /ai/conversations/{conversation_id}/query

Query In Conversation

Ask the assistant within a conversation. Normal messages, including images and PDFs, run the agent inline. Receipt extraction is an explicit ``document_mode=receipts`` workflow that creates a background reading job. Reads execute against the app the user sees and changes come back as pending actions to confirm. A failed run is stored as an assistant message so the thread keeps its history.

Parameters

NameInRequiredTypeDescription
conversation_idpathyesstring--

Request body

FieldTypeRequiredDescription
querystring--Query
file_idsarray of string, optional--File Ids
document_modestring--Document Mode

Responses

StatusDescriptionBody
200Successful Response--
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/conversations/:conversation_id/query \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

POST /ai/estimate-credits

Estimate Credits

Preview the relay's current per-file credit cost. Page counts remain informational; the cloud gateway charges one credit per model request/file, so local estimates must not maintain a second pricing formula that can drift from the authoritative meter.

Request body

FieldTypeRequiredDescription
file_idsarray of stringyesList of file IDs to estimate credit cost for

Responses

StatusDescriptionBody
200Successful ResponseEstimateResponse
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/estimate-credits \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

GET /ai/file/{file_id}

Ai File

Retrieve a previously uploaded file.

Parameters

NameInRequiredTypeDescription
file_idpathyesstring--

Responses

StatusDescriptionBody
200Successful Response--
422Validation ErrorHTTPValidationError

Example

curl -X GET http://localhost:8000/ai/file/:file_id \
  -H "Authorization: Bearer $TOKEN"

GET /ai/memory

Get Ai Memory

Return the per-company AI memory (notes and key-value facts).

Responses

StatusDescriptionBody
200Successful ResponseMemoryResponse

Example

curl -X GET http://localhost:8000/ai/memory \
  -H "Authorization: Bearer $TOKEN"

DELETE /ai/memory

Clear Ai Memory

Wipe all AI memory for this company.

Responses

StatusDescriptionBody
204Successful Response--

Example

curl -X DELETE http://localhost:8000/ai/memory \
  -H "Authorization: Bearer $TOKEN"

POST /ai/memory/kv

Set Ai Memory Kv

Set a key-value fact in AI memory (max 100 keys).

Request body

FieldTypeRequiredDescription
keystringyesKey
valuestringyesValue

Responses

StatusDescriptionBody
201Successful Responseobject
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/memory/kv \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

POST /ai/memory/notes

Add Ai Memory Note

Append a note to AI memory (max 50 notes, oldest trimmed).

Request body

FieldTypeRequiredDescription
contentstringyesContent

Responses

StatusDescriptionBody
201Successful Responseobject
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/memory/notes \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

POST /ai/query

Ai Query

Run a one-off read-only agent query against live canonical ERP APIs.

Request body

FieldTypeRequiredDescription
querystringyesNatural language question
file_idsarray of string, optional--List of file IDs returned from /ai/upload

Responses

StatusDescriptionBody
200Successful ResponseQueryResponse
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/query \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'

GET /ai/quota-status

Quota Status

Return current AI quota usage for the UI badge. Returns used/limit/topup/remaining/tier. Never raises - returns empty dict if gateway not configured (local install).

Responses

StatusDescriptionBody
200Successful Responseobject

Example

curl -X GET http://localhost:8000/ai/quota-status \
  -H "Authorization: Bearer $TOKEN"

POST /ai/upload

Ai Upload

Upload files for AI batch processing. Returns list of file IDs.

Responses

StatusDescriptionBody
201Successful Responseobject
422Validation ErrorHTTPValidationError

Example

curl -X POST http://localhost:8000/ai/upload \
  -H "Authorization: Bearer $TOKEN"

GET /ai/usage-stats

Usage Stats

Per-user AI usage for the current calendar month. Returns list of {user_id, user_name, query_count, credits_used, last_query_at}.

Responses

StatusDescriptionBody
200Successful Responseobject

Example

curl -X GET http://localhost:8000/ai/usage-stats \
  -H "Authorization: Bearer $TOKEN"