> For the complete documentation index, see [llms.txt](https://docs.cekat.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cekat.ai/api-documentation/ai/generate-an-ai-response-beta.md).

# Generate an AI response (beta)

Runs one of your AI agents on a chat history you provide and returns its reply, without sending anything to a contact. Use it to test an AI agent or to generate replies for your own channel.

The history must end with a message from the user. Each reply reports the AI credits it used. This endpoint is in beta and may change.

```json
{"openapi":"3.0.3","info":{"title":"Cekat Open API","version":"1.0.0"},"tags":[{"name":"AI","description":"Manage your AI agents' Q&A knowledge, test AI replies, and manage the OrderOnline integration."}],"servers":[{"url":"https://api.cekat.ai","description":"Production"}],"security":[{"CekatApiKey":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"CekatApiKey":{"type":"apiKey","in":"header","name":"api_key","description":"Your business's Cekat API key, from **Settings → Developers & API** in the Cekat dashboard (https://chat.cekat.ai/developers?section=apikeys). Available on the Business and Enterprise plans."},"BearerAuth":{"type":"http","scheme":"bearer","description":"The same Cekat API key, sent as `Authorization: Bearer YOUR_API_KEY`. Accepted only by endpoints under `/api/...`."}},"schemas":{"ApiError":{"type":"object","description":"Error body returned by the `/api/...` endpoints.","properties":{"success":{"type":"boolean"},"message":{"type":"string"},"statusCode":{"type":"integer"},"error":{"type":"object","properties":{"message":{"type":"string"}}},"correlationId":{"type":"string","description":"Request ID. Include it when contacting Cekat support."}}},"RateLimitError":{"type":"object","properties":{"message":{"type":"string"}}}},"responses":{"ApiUnauthorized":{"description":"The API key is missing or invalid.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}},"TooManyRequests":{"description":"Rate limit exceeded. Wait and retry.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitError"}}}}}},"paths":{"/api/ai_response/beta":{"post":{"tags":["AI"],"operationId":"GenerateAiResponse","summary":"Generate an AI response (beta)","description":"Runs one of your AI agents on a chat history you provide and returns its reply, without sending anything to a contact. Use it to test an AI agent or to generate replies for your own channel.\n\nThe history must end with a message from the user. Each reply reports the AI credits it used. This endpoint is in beta and may change.\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["ai_agent_id","messages"],"properties":{"ai_agent_id":{"type":"string","format":"uuid"},"messages":{"type":"array","description":"The chat history, oldest first. The last message must be from the user.","items":{"type":"object","properties":{"role":{"type":"string","enum":["user","assistant"]},"message":{"type":"string"},"created_at":{"type":"string","format":"date-time"}}}},"chat_data":{"type":"object","additionalProperties":true,"description":"Data the AI agent collected earlier in this chat. Send back the `chat_data` from the previous response to continue the same chat."}}}}}},"responses":{"200":{"description":"The AI agent's reply.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"messages":{"type":"array","description":"The reply, plus system notes when the AI agent ran tools.","items":{"type":"object","properties":{"role":{"type":"string","enum":["assistant","system"]},"content":{"type":"string"},"credits_used":{"type":"number","description":"AI credits used for this reply."}}}},"chat_data":{"type":"object","additionalProperties":true}}}}}},"400":{"description":"`ai_agent_id` is missing, `messages` is not an array, or there is no user message.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}},"401":{"$ref":"#/components/responses/ApiUnauthorized"},"429":{"$ref":"#/components/responses/TooManyRequests"},"502":{"description":"The AI service is unavailable. Retry later.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}}}}}}}
```
