The same consultant that works in the cabinet is available from your application. You create a session, send a message, and the assistant's answer arrives piece by piece over an open stream.
Needs the tools:chat scope. Base URL: https://developers.grem.capital/api/v1.
How it works
- Create a session - it holds the conversation's context.
- Open the event stream for that session.
- Send a message.
- The answer arrives on the stream in pieces until it is finished.
Order matters: open the stream before you send the message, otherwise the first pieces of the answer go past you.
Sessions
POST /chat/sessions create
GET /chat/sessions list
PATCH /chat/sessions/{id} rename, pin
DELETE /chat/sessions/{id} move to the archive
Creating one:
curl -X POST https://developers.grem.capital/api/v1/chat/sessions \
-H "Authorization: Bearer gsk_live_xxx" \
-H "Content-Type: application/json" \
-d '{"title":"Client question about a mortgage"}'
The response carries the session id, which you pass into every call that follows.
The API gives you the general consultant. The autoresponder mode that works inside the cabinet's CRM cannot be switched on from outside.
Send a message
curl -X POST https://developers.grem.capital/api/v1/chat/messages \
-H "Authorization: Bearer gsk_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"sessionId": "…",
"text": "What does a two-room flat in Podil cost?",
"clientMessageId": "msg-0001"
}'
clientMessageId is your own id for the message. It ties what you sent to what arrives on the stream, so nothing is shown twice when the connection is re-established.
The optional style field sets the length of the answer: short, normal or detailed.
The answer stream
GET /chat/stream?sessionId=…
Authorization: Bearer gsk_live_...
Accept: text/event-stream
The connection is long-lived and events arrive as the answer is generated:
| Event | What it means |
|---|---|
assistant.started | the assistant began answering; text pieces follow |
assistant.delta | the next piece of text, in the delta field |
assistant.done | the answer is complete; text holds the whole thing |
If the connection drops, reconnect with the same sessionId: the server replays the current turn from the start. That is why assistant.started should clear the text accumulated for that message, or it will be doubled.
History
GET /chat/history?sessionId=…&limit=50
Returns the session's stored messages. Use it to restore the conversation after your interface reloads.
What it costs
Only sending a message (POST /chat/messages) is billed. Creating a session, listing sessions, the history and the stream itself are free and are not counted as API calls.
Related articles
- TypeScript SDK - a ready client that subscribes to the stream.
- Errors - what the refusal codes mean.
- Tools over the API - the platform's other tools.