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

# Add File

> Upload a document file to an agent's knowledge base.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.thinnest.ai/knowledge/add-file \
    -H "Authorization: Bearer $THINNESTAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "agent_id": "ag_c47e7c97_b2f2",
    "file": "(multipart file upload)"
  }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.thinnest.ai/knowledge/add-file"
  headers = {
      "Authorization": "Bearer " + "YOUR_THINNESTAI_API_KEY",
      "Content-Type": "application/json",
  }

  payload = {
    "agent_id": "ag_c47e7c97_b2f2",
    "file": "(multipart file upload)"
  }

  response = requests.post(url, headers=headers, json=payload)
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://api.thinnest.ai/knowledge/add-file", {
    method: "POST",
    headers: {
      "Authorization": "Bearer " + "YOUR_THINNESTAI_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
    "agent_id": "ag_c47e7c97_b2f2",
    "file": "(multipart file upload)"
  }),
  });

  const data = await response.json();
  console.log(data);
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "fmt"
      "io"
      "net/http"
  )

  func main() {
      payload := []byte(`{
    "agent_id": "ag_c47e7c97_b2f2",
    "file": "(multipart file upload)"
  }`)
      req, _ := http.NewRequest("POST", "https://api.thinnest.ai/knowledge/add-file", bytes.NewBuffer(payload))
      req.Header.Set("Authorization", "Bearer YOUR_THINNESTAI_API_KEY")
      req.Header.Set("Content-Type", "application/json")

      resp, err := http.DefaultClient.Do(req)
      if err != nil { panic(err) }
      defer resp.Body.Close()
      body, _ := io.ReadAll(resp.Body)
      fmt.Println(string(body))
  }
  ```
</RequestExample>

***

## Request

This endpoint uses `multipart/form-data` for file uploads.

### Form Fields

| Field      | Type   | Required | Description                    |
| ---------- | ------ | -------- | ------------------------------ |
| `agent_id` | string | **Yes**  | The agent's public ID (`ag_*`) |
| `file`     | file   | **Yes**  | The file to upload             |

### Supported Formats

| Format   | Extensions      | Max Size |
| -------- | --------------- | -------- |
| PDF      | `.pdf`          | 50 MB    |
| Word     | `.docx`, `.doc` | 50 MB    |
| Text     | `.txt`          | 10 MB    |
| Markdown | `.md`           | 10 MB    |
| CSV      | `.csv`          | 50 MB    |
| Excel    | `.xlsx`, `.xls` | 50 MB    |
| JSON     | `.json`         | 10 MB    |

***

## cURL Example

```bash theme={null}
curl -X POST https://api.thinnest.ai/knowledge/add-file \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "agent_id=ag_c47e7c97_b2f2" \
  -F "file=@/path/to/document.pdf"
```

***

## Response `201`

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": 3,
    "name": "document.pdf",
    "type": "file",
    "status": "processing",
    "created_at": "2026-03-07T14:00:00Z"
  }
  ```
</ResponseExample>

The file is processed asynchronously. Check status via [List Sources](/api-reference/knowledge/list).

***

## Errors

| Code  | Description                       |
| ----- | --------------------------------- |
| `401` | Missing or invalid authentication |
| `404` | Agent not found                   |
| `413` | File too large                    |
| `415` | Unsupported file type             |


## OpenAPI

````yaml POST /knowledge/add-file
openapi: 3.1.0
info:
  title: ThinnestAI API
  description: REST API for ThinnestAI — build, deploy, and manage AI agents.
  version: 1.0.0
servers: []
security: []
tags:
  - name: Agents
    description: Create, configure, and manage AI agents
  - name: Chat
    description: Send messages and get AI responses from agents
  - name: Knowledge
    description: Upload files, URLs, and text to agent knowledge bases
  - name: Sessions
    description: View and manage chat sessions and message history
  - name: Voice
    description: Start and manage voice call sessions
  - name: Recordings
    description: Manage voice call recordings
  - name: Campaigns
    description: Create and run automated outreach campaigns
  - name: Webhooks
    description: Register webhook endpoints for real-time event notifications
  - name: Evaluations
    description: Run and track agent evaluation benchmarks
  - name: Analytics
    description: Query agent performance metrics and usage data
  - name: Agent Tools
    description: View and manage tools attached to agents
  - name: BYOK
    description: >-
      Bring Your Own Key — manage credentials for LLM/STT/TTS providers,
      telephony BYOK (Vobiz/Twilio/Plivo/Exotel/Telnyx), and tool-specific BYOK
      (Razorpay UPI Payment, Surepass Aadhaar eKYC)
paths:
  /knowledge/add-file:
    post:
      tags:
        - Knowledge
      summary: Add File Endpoint
      description: Add a file to the knowledge base with secure billing.
      operationId: add_file_endpoint_knowledge_add_file_post
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: >-
                #/components/schemas/Body_add_file_endpoint_knowledge_add_file_post
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    Body_add_file_endpoint_knowledge_add_file_post:
      properties:
        file:
          type: string
          format: binary
          title: File
      type: object
      required:
        - file
      title: Body_add_file_endpoint_knowledge_add_file_post
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````