> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memic.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat over your documents

> Grounded question-answering with citations back to source files.

The chat endpoint takes a user question, retrieves relevant passages from
your indexed documents, and generates a grounded answer with citations.
It's a turnkey RAG pipeline — no prompt engineering, no chunk assembly, no
citation formatting.

## The basics

```python theme={null}
response = client.chat("Summarize our refund policy in three bullet points")

print(response.answer)
for citation in response.citations:
    print(f"  → {citation.file_name} (p. {citation.page})")
```

Or via HTTP:

```bash theme={null}
curl https://api.memic.ai/api/v1/chat \
  -H "X-API-Key: $MEMIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Summarize our refund policy"}
    ]
  }'
```

## Multi-turn conversations

Pass the full message history in each call. Memic is stateless — every
request must include the complete conversation context:

```python theme={null}
messages = []

messages.append({"role": "user", "content": "What's our refund policy?"})
response = client.chat(messages=messages)
print(response.answer)
messages.append({"role": "assistant", "content": response.answer})

messages.append({"role": "user", "content": "What about digital products?"})
response = client.chat(messages=messages)
print(response.answer)
```

## Citations

Every chat response includes structured citations pointing back to the
source documents:

```json theme={null}
{
  "answer": "Customers may request a refund within 30 days of purchase...",
  "citations": [
    {
      "file_id": "...",
      "file_name": "refund-policy.pdf",
      "page": 4,
      "passage": "Customers may request..."
    }
  ]
}
```

Use these to render "read more" links in your UI or verify the LLM isn't
hallucinating.

## When to use chat vs search

* **Use `search`** when you want passages to render as a list, or when you
  need raw retrieved content to feed into your own prompt
* **Use `chat`** when you want an answer composed for you, with citations

Chat internally calls search and uses the results as context for an LLM.
If you want full control over the LLM or prompt, use `search` + your own
LLM call.

## Related

<CardGroup cols={2}>
  <Card title="Recipe: Chatbot" icon="robot" href="/recipes/chatbot-with-memory">
    A complete chatbot with memory walkthrough.
  </Card>

  <Card title="API reference" icon="code" href="/api-reference/introduction">
    Full chat endpoint docs.
  </Card>
</CardGroup>
