# Upload File

Upload an image file that can later be referenced by its `file_id` in chat completion requests.

Supported formats: JPEG, PNG, GIF, and WebP. The format is detected from the file content. See the [Files API guide](https://api-docs.deepseek.com/guides/files_api.md) for details.

To upload documents, set `purpose` to `text_recognition` or `rich_layout_recognition` and send it before the `file` field. See the [File Parsing guide](https://api-docs.deepseek.com/guides/document_parsing.md).

## Endpoint

```http
POST /files
```

operationId: `createFile`

### Servers

- `https://api.deepseek.com`

## Authentication

### Alternative 1

**bearerAuth**

`Authorization: Bearer <API_KEY>`

```yaml
type: http
scheme: bearer
```

## Request body

**required**

### multipart/form-data

- Reference: [CreateFileRequest](#schema-create-file-request) (`#/components/schemas/CreateFileRequest`)

## Responses

### 200

OK, returns the uploaded `file object`.

#### application/json

- Reference: [FileObject](#schema-file-object) (`#/components/schemas/FileObject`)

**Example**

```json
{
  "id": "file-api-0a1b2c3d4e5f60718293a4b5c6d7e8f9",
  "object": "file",
  "bytes": 102400,
  "created_at": 1700000000,
  "filename": "image.jpg",
  "purpose": "user_data"
}
```

## Code samples

### curl

```bash
# Set DEEPSEEK_API_KEY to your API key before running this example.
# Set DEEPSEEK_FILE_PATH to a local JPEG, PNG, GIF, or WebP image.
curl --silent --show-error --max-time 60 "https://api.deepseek.com/files" \
  --header "Authorization: Bearer ${DEEPSEEK_API_KEY}" \
  --form "purpose=user_data" \
  --form "file=@${DEEPSEEK_FILE_PATH}"
```

### Python — OpenAI SDK

```python
# Set DEEPSEEK_API_KEY to your API key before running this example.
# Set DEEPSEEK_FILE_PATH to a local JPEG, PNG, GIF, or WebP image.
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["DEEPSEEK_API_KEY"],
    base_url="https://api.deepseek.com",
    timeout=60.0,
)

with open(os.environ["DEEPSEEK_FILE_PATH"], "rb") as image:
    uploaded = client.files.create(file=image, purpose="user_data")
print(uploaded.model_dump_json(indent=2))
```

## Referenced schemas

### schema-create-file-request

**CreateFileRequest** — `#/components/schemas/CreateFileRequest`

- `type`: `object`

- `required`: `["file","purpose"]`

- **Properties**

  - **`purpose`** (required)

    The intended purpose of the uploaded file. When uploading a document, send this field before `file`. See the [Files API guide](https://api-docs.deepseek.com/guides/files_api.md) for the file types each purpose accepts.

    - `type`: `string`

    - `enum`: `["user_data","text_recognition","rich_layout_recognition"]`

  - **`file`** (required)

    The file to upload. The accepted file types depend on `purpose`.

    - `type`: `string`

    - `format`: `binary`

  - **`expires_after[anchor]`** (optional)

    The anchor for the expiration. Must be `created_at` if provided, and is required together with `expires_after[seconds]`.

    - `type`: `string`

    - `enum`: `["created_at"]`

  - **`expires_after[seconds]`** (optional)

    The lifetime of the file in seconds, between 3600 (1 hour) and 2592000 (30 days). Required together with `expires_after[anchor]`. Omit both `expires_after` fields to keep the file permanently.

    - `type`: `integer`

    - `minimum`: `3600`

    - `maximum`: `2592000`

### schema-file-object

**FileObject** — `#/components/schemas/FileObject`

Describes a file that has been uploaded to the Files API. A file uploaded with an OCR purpose is returned only after parsing succeeds.

- `type`: `object`

- `required`: `["id","object","bytes","created_at","filename","purpose"]`

- **Properties**

  - **`id`** (required)

    The file identifier, of the form `file-api-...`, which can be referenced in chat completion requests.

    - `type`: `string`

  - **`object`** (required)

    The object type, which is always `file`.

    - `type`: `string`

    - `enum`: `["file"]`

  - **`bytes`** (required)

    The size of the file in bytes.

    - `type`: `integer`

  - **`created_at`** (required)

    The Unix timestamp (in seconds) of when the file was created.

    - `type`: `integer`

  - **`filename`** (required)

    The name of the file.

    - `type`: `string`

  - **`purpose`** (required)

    The intended purpose of the file.

    - `type`: `string`

    - `enum`: `["user_data","text_recognition","rich_layout_recognition"]`

  - **`expires_at`** (optional)

    The Unix timestamp (in seconds) of when the file expires. Only present when an expiration was set at upload time.

    - `type`: `integer`
