> This is a page from the ElevenLabs documentation. For an index of the documentation, fetch https://elevenlabs.io/docs/llms.txt.

# Upload Knowledge Source

POST https://api.elevenlabs.io/v1/reception/knowledge-sources
Content-Type: multipart/form-data

Upload a file as a knowledge source

Reference: https://elevenlabs.io/docs/api-reference/reception/knowledge-sources/upload

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Headers

- `xi-workspace-id` (string, required) — The customer workspace a reseller's API key acts on.

### Body (multipart/form-data)

This endpoint expects a multipart form containing a file.

- `file` (file, required) — The document the receptionist should learn from.

## Response

### 200

Successful Response

- `id` (string, required) — The knowledge source's ID.
- `source_type` (enum, optional, default: file) — Whether the source is an uploaded file or a web page or site.
  - Allowed values: `file`, `url`
- `source_url` (string, optional, nullable) — The page or site URL for 'url' sources.
- `last_scraped_at_unix` (integer, optional, nullable) — When the URL was last read, as a Unix timestamp in seconds.
- `original_filename` (string, optional, default: ) — The uploaded file's name for 'file' sources; empty for URLs.
- `content_type` (string, optional, default: ) — The uploaded file's MIME type; empty for URLs.
- `file_size_bytes` (integer, optional, default: 0) — The uploaded file's size in bytes; 0 for URLs.
- `status` (enum, optional, default: processing) — Where processing stands: 'processing', 'ready' or 'error'.
  - Allowed values: `processing`, `ready`, `error`
- `error_message` (string, optional, nullable) — Why processing failed, when status is 'error'.
- `failure_reason` (enum, optional, nullable) — Machine-readable cause of the failure, when status is 'error'.
  - Allowed values: `blocked_url`, `dns_failure`, `host_unreachable`, `access_refused`, `crawl_timeout`, `no_pages`, `no_content`, `upstream_timeout`, `upstream_error`, `unknown`
- `crawl_entire_site` (boolean, optional, default: false) — Whether the whole site was crawled rather than the single page at source_url.
- `scraped_pages_count` (integer, optional, default: 0) — How many pages were read for 'url' sources.
- `content_preview` (string, optional, nullable) — A short plain-text preview of the content.
- `processing_started_at_unix` (integer, optional, nullable) — When processing started, as a Unix timestamp in seconds.
- `created_at_unix` (integer, optional) — When this was created, as a Unix timestamp in seconds.
- `updated_at_unix` (integer, optional) — When this was last updated, as a Unix timestamp in seconds.

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)

### ValidationErrorLocItems

- string
- integer

## Examples

**Request**

```json
{
  "file": "<file: string>"
}
```

**Response**

```json
{
  "id": "ksource_4801jx8k3m5n7p9q2r4s6t8v0w2y",
  "source_type": "file",
  "source_url": "https://example.com",
  "last_scraped_at_unix": 1767225600,
  "original_filename": "price-list.pdf",
  "content_type": "application/pdf",
  "file_size_bytes": 204800,
  "status": "processing",
  "error_message": "We couldn't reach that website.",
  "failure_reason": "blocked_url",
  "crawl_entire_site": false,
  "scraped_pages_count": 12,
  "content_preview": "Welcome to Main Street Salon. We offer haircuts, color and styling.",
  "processing_started_at_unix": 1767225600,
  "created_at_unix": 1767225600,
  "updated_at_unix": 1767225600
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/reception/knowledge-sources"

files = { "file": "open('string', 'rb')" }
headers = {"xi-workspace-id": "xi-workspace-id"}

response = requests.post(url, files=files, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/reception/knowledge-sources';
const form = new FormData();
form.append('file', 'string');

const options = {method: 'POST', headers: {'xi-workspace-id': 'xi-workspace-id'}};

options.body = form;

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.elevenlabs.io/v1/reception/knowledge-sources"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("xi-workspace-id", "xi-workspace-id")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/reception/knowledge-sources")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["xi-workspace-id"] = 'xi-workspace-id'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.elevenlabs.io/v1/reception/knowledge-sources")
  .header("xi-workspace-id", "xi-workspace-id")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.elevenlabs.io/v1/reception/knowledge-sources', [
  'multipart' => [
    [
        'name' => 'file',
        'filename' => 'string',
        'contents' => null
    ]
  ]
  'headers' => [
    'xi-workspace-id' => 'xi-workspace-id',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/reception/knowledge-sources");
var request = new RestRequest(Method.POST);
request.AddHeader("xi-workspace-id", "xi-workspace-id");
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["xi-workspace-id": "xi-workspace-id"]
let parameters = [
  [
    "name": "file",
    "fileName": "string"
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/reception/knowledge-sources")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```