# Upload Document

`POST /api/v1/knowledge/{id}/documents`

## Description
Upload a document to a knowledge base. The document will be processed asynchronously (chunked and embedded). Files must contain at least one byte and cannot exceed 100MB. Zero-byte files return HTTP 400 with error 'File cannot be empty' before storage or document processing begins.

## Parameters

- **id** (path) (required) — `string`: Knowledge base ID.

## Request Body

## Responses

### 200 — Document uploaded successfully. Processing will begin shortly.

```json
{
  "type": "object",
  "properties": {
    "success": {
      "type": "boolean",
      "description": "Whether the request was successful."
    },
    "data": {
      "type": "object",
      "properties": {
        "document": {
          "type": "object",
          "description": "A document in a knowledge base.",
          "properties": {
            "id": {
              "type": "string",
              "description": "Unique document identifier."
            },
            "knowledgeBaseId": {
              "type": "string",
              "description": "Knowledge base this document belongs to."
            },
            "filename": {
              "type": "string",
              "description": "Original filename."
            },
            "fileSize": {
              "type": "integer",
              "description": "File size in bytes."
            },
            "mimeType": {
              "type": "string",
              "description": "MIME type of the file."
            },
            "processingStatus": {
              "type": "string",
              "enum": [
                "pending",
                "processing",
                "completed",
                "failed"
              ],
              "description": "Current processing status."
            },
            "chunkCount": {
              "type": "integer",
              "description": "Number of chunks created from this document."
            },
            "tokenCount": {
              "type": "integer",
              "description": "Total token count."
            },
            "characterCount": {
              "type": "integer",
              "description": "Total character count."
            },
            "enabled": {
              "type": "boolean",
              "description": "Whether the document is enabled for search."
            },
            "createdAt": {
              "type": "string",
              "format": "date-time",
              "description": "ISO 8601 timestamp when the document was uploaded."
            }
          }
        },
        "message": {
          "type": "string",
          "description": "Human-readable confirmation message."
        }
      },
      "description": "Response payload containing the uploaded document."
    }
  }
}
```

### 400 — Invalid request parameters. Check the details array for specific validation errors.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Human-readable error message describing the validation failure."
    },
    "details": {
      "type": "array",
      "description": "List of specific validation errors with field-level details.",
      "items": {
        "type": "object"
      }
    }
  }
}
```

### 401 — Invalid or missing API key. Ensure the X-API-Key header is set with a valid key.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Human-readable error message."
    }
  }
}
```

### 403 — Access denied. You do not have permission to access this resource. For audit log endpoints, this requires an Enterprise subscription and organization admin/owner role.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Human-readable error message."
    }
  }
}
```

### 404 — The requested resource was not found. Verify the ID is correct and belongs to your workspace.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Human-readable error message."
    }
  }
}
```

### 409 — A file with the same name already exists.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Error message indicating a file with the same name already exists."
    }
  }
}
```

### 413 — Storage limit exceeded for the workspace.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Error message indicating the workspace storage limit has been exceeded."
    }
  }
}
```

### 415 — Unsupported file type. See error message for supported types.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Error message indicating the file type is not supported."
    }
  }
}
```

### 429 — Rate limit exceeded. Wait for the duration specified in the Retry-After header before retrying.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Human-readable error message with rate limit details."
    }
  }
}
```
