cURL
curl --request POST \ --url https://api.chaindesk.ai/agents/query/{id} \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "query": "<string>", "conversationId": "<string>", "visitorId": "<string>", "temperature": 123, "streaming": true, "promptType": "raw", "promptTemplate": "<string>", "filters": { "custom_ids": [ "<string>" ], "datasource_ids": [ "<string>" ] } }'
{ "answer": "<string>", "conversationId": "<string>", "visitorId": "<string>", "sources": [ {} ] }
import { EventStreamContentType, fetchEventSource, } from '@microsoft/fetch-event-source'; let buffer = ''; let bufferEndpointResponse = ''; const ctrl = new AbortController(); await fetchEventSource(queryAgentURL, { method: 'POST', headers: { 'Content-Type': 'application/json', }, signal: ctrl.signal, body: JSON.stringify({ streaming: true, query, conversationId, visitorId, }), async onopen(response) { if (response.status === 402) { throw new ApiError(ApiErrorType.USAGE_LIMIT); } }, onmessage: (event) => { if (event.data === '[DONE]') { // End of stream ctrl.abort(); try { const { sources, conversationId, visitorId } = JSON.parse( bufferEndpointResponse ) as ChatResponse; } catch {} } else if (event.data?.startsWith('[ERROR]')) { // ... } else if (event.event === "endpoint_response") { bufferEndpointResponse += event.data; } else if (event.event === "answer") { buffer += event.data; // ... } }, });
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Bearer <token>
<token>
ID of the agent
Success
The response is of type object.
object