---
title: "Chat"
method: POST
path: "/chat"
tags: ["chat"]
---

# Chat

`POST /chat`

Chat endpoint using LiteLLM with GitHub Copilot and optional RAG.

This endpoint requires the user to be authenticated with both Extralit
and GitHub (via the /auth/github/login flow).

If dataset_id is provided, the endpoint will perform RAG retrieval:
1. Generate embedding for the user's query
2. Search for relevant documents in the dataset
3. Inject retrieved context into the system prompt

Args:
    request: Chat request with model, messages, and optional dataset_id
    current_user: Authenticated Extralit user
    db: Database session (injected for RAG)
    search_engine: Search engine instance (injected for RAG)

Returns:
    StreamingResponse with chat completion

Raises:
    HTTPException: If user is not authenticated with GitHub

## Request body

- ChatRequest — Request model for chat endpoint.
  - `model` string — Model to use for chat (e.g., 'copilot')
  - `messages` ChatMessage[], required — List of chat messages
    - `role` string, required — Role of the message sender (user, assistant, system)
    - `content` string, required — Content of the message
  - `stream` boolean — Whether to stream the response
  - `dataset_id` string, uuid, nullable — Optional dataset ID for RAG retrieval
  - `top_k` integer — Number of documents to retrieve for RAG

## Response `200`

Successful Response

- unknown

## Other responses

- `400` — Bad Request
- `403` — Forbidden
- `404` — Not Found
- `409` — Conflict
- `422` — Unprocessable Content
- `500` — Internal Server Error

---

[API](https://skmtc.net/hf/apis/extralit-v1.md) · [All operations](https://skmtc.net/hf/apis/extralit-v1/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/hf/extralit-v1/versions/e9da3a893a88/schema)
