---
title: "RAG search with AI-generated answer"
method: POST
path: "/api/rag/{project_id}/ai-search"
tags: ["RAG"]
---

# RAG search with AI-generated answer

`POST /api/rag/{project_id}/ai-search`

## Request

- Base URL: `https://core.blink.new`
- URL: `https://core.blink.new/api/rag/{project_id}/ai-search`
- Auth: HTTP bearer

Search for relevant chunks and generate an answer using LLM

## Path parameters

- `project_id` string, required

## Request body

- object
  - `collection_id` string
  - `collection_name` string
  - `query` string, required
  - `max_results` integer
  - `model` string
  - `system_prompt` string
  - `stream` boolean

## Response `200`

AI-generated answer with sources. With `stream: true` the body is the answer as plain text and sources arrive in the `X-RAG-Sources` header. A model failure before the first chunk returns the JSON error instead of an empty 200.

## Other responses

- `400`: Invalid request, or, when zero data retention is enabled for AI requests, the model cannot run under it.
- `401`: Authentication required or invalid API key
- `500`: AI search failed. Non-streaming failures return the flat `ErrorResponse` (`{ "error": "AI search failed" }`); a streaming failure before the first chunk returns the `AIErrorResponse` shape.

---

[API](https://skmtc.dev/blink/apis/blink-apis.md) - [All operations](https://skmtc.dev/blink/apis/blink-apis/llms.txt) - [OpenAPI document](https://skmtc.dev/blink/apis/blink-apis/revisions/4c59c706078e?raw)
