# Extract text for Open WebUI

Target of the External content extraction engine in Open WebUI: set the engine URL to https://api.switchfile.io/v1/openwebui and the API key. The raw file is the request body, X-Filename names it. The answer holds the document as Markdown (plain text for formats without a Markdown conversion) and is billed like a conversion to Markdown. Conversions that take longer than 90 seconds are cancelled with 504 and cost nothing.

`PUT https://api.switchfile.io/v1/openwebui/process`

Needs an API key: `Authorization: Bearer YOUR_API_KEY`. See [Authentication](https://switchfile.io/docs/authentication).

## Example

cURL:

```bash
curl -X PUT "https://api.switchfile.io/v1/openwebui/process" \
  -H "Authorization: Bearer $SWITCHFILE_API_KEY" \
  --upload-file lecture.mov
```

Node.js:

```js
import { readFile } from "node:fs/promises";

const res = await fetch("https://api.switchfile.io/v1/openwebui/process", {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.SWITCHFILE_API_KEY}`,
  },
  body: await readFile("lecture.mov"),
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
console.log(await res.json());
```

PHP:

```php
<?php
$ch = curl_init('https://api.switchfile.io/v1/openwebui/process');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_POSTFIELDS => file_get_contents('lecture.mov'),
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('SWITCHFILE_API_KEY'),
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

if ($status >= 400) {
    throw new RuntimeException("HTTP $status: $response");
}
print_r(json_decode($response, true));
```

Python:

```python
import os
import requests

res = requests.put(
    "https://api.switchfile.io/v1/openwebui/process",
    headers={"Authorization": f"Bearer {os.environ['SWITCHFILE_API_KEY']}"},
    data=open("lecture.mov", "rb"),
)
res.raise_for_status()
print(res.json())
```

## Parameters

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `X-Filename` | string | no | File name, URL-encoded. The extension decides the input format; without one, Content-Type is used (example: annual%20report.pdf) |

## Request body

The file as the raw request body. Content-Type is its MIME type

The file as the raw request body.

## Responses

### 200: The document as Markdown

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `metadata` | object | yes |  |
| `metadata.conversion_id` | string | yes | ID of the conversion, as in GET /v1/conversions/{id} |
| `metadata.credits` | string (integer) \| integer | yes | Credits used |
| `metadata.format` | string | yes | md or txt |
| `metadata.incomplete` | boolean | no | Set when parts of the file could not be converted; page_content then starts with a line saying so |
| `metadata.notes` | string[] | no | What is missing or was changed, in English |
| `metadata.source` | string | yes | File name as sent in X-Filename |
| `page_content` | string | yes | The document as Markdown (plain text for formats without a Markdown conversion) |

Example (application/json):

```json
{
  "page_content": "# Annual report\n\n| Year | Revenue |\n| --- | --- |\n| 2025 | 1.2 M |\n",
  "metadata": {
    "source": "annual report.pdf",
    "conversion_id": "0b8a7c1e-5d0f-4a51-9f39-2f7f4c1d9a10",
    "format": "md",
    "credits": 1
  }
}
```

### 401: The API key is missing or not valid (`UNAUTHENTICATED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-unauthenticated",
  "title": "Unauthenticated",
  "status": 401,
  "code": "UNAUTHENTICATED",
  "detail": "Missing or invalid API key. Send it as Authorization: Bearer <key>. No key yet? Follow get_a_key.",
  "get_a_key": {
    "summary": "No API key yet? Get one with two requests, without a browser.",
    "steps": [
      {
        "method": "POST",
        "url": "https://api.switchfile.io/v1/signup",
        "body": {
          "email": "you@example.com",
          "accept_terms": true
        },
        "result": "We email a code with 8 digits to the address."
      },
      {
        "method": "POST",
        "url": "https://api.switchfile.io/v1/signup/verify",
        "body": {
          "email": "you@example.com",
          "code": "12345678",
          "accept_terms": true
        },
        "result": "Your API key, shown once. Send it as Authorization: Bearer <key>."
      }
    ],
    "terms_url": "https://switchfile.io/terms",
    "privacy_url": "https://switchfile.io/privacy",
    "docs_url": "https://switchfile.io/docs/authentication#get-an-api-key-without-a-browser"
  }
}
```

### 402: Today's free quota is used up and there are not enough credits (`CREDITS_EXCEEDED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-credits-exceeded",
  "title": "Credits exceeded",
  "status": 402,
  "code": "CREDITS_EXCEEDED",
  "detail": "Today's free quota is used up and there are not enough credits left."
}
```

### 403: The account converts files without storing them (`STORAGE_DISABLED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-storage-disabled",
  "title": "Storage disabled",
  "status": 403,
  "code": "STORAGE_DISABLED",
  "detail": "This account converts files without storing them (no_store). The Open WebUI endpoint keeps the file for the usual retention period, so it is not available for this account."
}
```

### 404: Does not exist for this account

### 413: The request or the file is too large (`FILE_TOO_LARGE`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-file-too-large",
  "title": "File too large",
  "status": 413,
  "code": "FILE_TOO_LARGE",
  "detail": "The file is larger than the allowed maximum."
}
```

### 415: The file type cannot be converted to text (`UNSUPPORTED_MEDIA_TYPE`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-unsupported-media-type",
  "title": "Unsupported media type",
  "status": 415,
  "code": "UNSUPPORTED_MEDIA_TYPE",
  "detail": "MP3 files cannot be converted to text. Use POST /v1/convert for other targets."
}
```

### 422: The file is empty, or the conversion failed (`INVALID_DATA`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-invalid-data",
  "title": "Invalid data",
  "status": 422,
  "code": "INVALID_DATA",
  "detail": "The request contains invalid data.",
  "errors": {
    "to": [
      "Expected string"
    ]
  }
}
```

### 429: Too many requests or a daily quota is used up. See Retry-After (`RATE_LIMIT_EXCEEDED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-rate-limit-exceeded",
  "title": "Rate limit exceeded",
  "status": 429,
  "code": "RATE_LIMIT_EXCEEDED",
  "detail": "Too many requests. Try again in 12 seconds."
}
```

### 504: The conversion took longer than 90 seconds and was cancelled without cost (`WAIT_TIMEOUT`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-wait-timeout",
  "title": "Wait timeout",
  "status": 504,
  "code": "WAIT_TIMEOUT",
  "detail": "The conversion did not finish within 90 seconds and was cancelled. Convert large files with POST /v1/convert and fetch the result when it is done.",
  "conversion_id": "0b8a7c1e-5d0f-4a51-9f39-2f7f4c1d9a10"
}
```

Error bodies and codes are explained in [Errors](https://switchfile.io/docs/errors).
