# Upload a file

`POST https://api.morevoice.ai/v1/files`

Uploads a document for a later request, as multipart/form-data (a `file` part and `purpose`) or as JSON with the file base64: a PDF, JPEG or PNG of up to 10 MB (the type is read from the file itself). Today's purpose is `port_document`: the signed LOA and the latest invoice of a port (POST /v1/ports). The file is stored encrypted; a file is used by one request, and an unused one is deleted after 7 days. At most 50 unused files at a time. Needs a live key and number porting on.

Authenticate with a secret API key: `Authorization: Bearer $MOREVOICE_API_KEY`.

Operation ID: `files_create`.

## Parameters

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `MoreVoice-Version` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `Idempotency-Key` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |

## Request body

Required, `application/json` or `multipart/form-data`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `purpose` | `"port_document"` | yes | What the file is for: `port_document`. |
| `file` | `object` | yes | The document. JSON requests send it base64; multipart/form-data requests send a `file` part. |
| `file.content_base64` | `string` | yes | The file, base64: a PDF, JPEG or PNG of up to 10 MB. |
| `file.filename` | `string` | no | — |

Example:

```json
{
  "file": {
    "content_base64": "JVBERi0xLjQKJcfsj6IK",
    "filename": "loa-signed.pdf"
  },
  "purpose": "port_document"
}
```

## Responses

### 201 Created

Created. Returns `File`.

| Field | Type | Description |
| --- | --- | --- |
| `object` | `"file"` | — |
| `id` | `string` | A file ID (prefix `file_`). |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `purpose` | `"port_document"` | What the file is for: `port_document` (a port's signed LOA or latest invoice). |
| `filename` | `string` | — |
| `mime_type` | `string` | application/pdf, image/jpeg or image/png (read from the file itself). |
| `size_bytes` | `integer` | — |
| `sha256` | `string` | SHA-256 of the file's bytes (hex). |
| `used` | `boolean` | A request took it (a file is used once). |
| `expires_at` | `string \| null` | An unused file is deleted after this; null once used. |
| `created` | `string` | An ISO-8601 timestamp in UTC. |

Example:

```json
{
  "created": "2026-11-23T09:00:00.000Z",
  "expires_at": "2026-11-30T09:00:00.000Z",
  "filename": "loa-signed.pdf",
  "id": "file_3NcP7sQ2wLm9TzXb4RkVu",
  "livemode": true,
  "mime_type": "application/pdf",
  "object": "file",
  "purpose": "port_document",
  "sha256": "9f2c6b1e0d4a7c3b8e5f1a2d6c9b0e3f7a4d1c8b5e2f9a6d3c0b7e4f1a8d5c2b",
  "size_bytes": 184320,
  "used": false
}
```

### 400 Bad Request

The request is invalid: a parameter is missing, malformed or unknown, or the version header is unknown. Returns `ErrorEnvelope`.

### 401 Unauthorized

No valid API key was sent. Returns `ErrorEnvelope`.

### 403 Forbidden

The key may not do this (a missing scope, a plan limit, or a compliance block). Returns `ErrorEnvelope`.

### 404 Not Found

No object with this ID (in the path or the body) exists in this organisation and mode. Returns `ErrorEnvelope`.

### 409 Conflict

The request conflicts with the object's state, or the Idempotency-Key was reused with other parameters. Returns `ErrorEnvelope`.

### 413 Payload Too Large

The request body is larger than the endpoint accepts, or has more parts or files than it takes. Returns `ErrorEnvelope`.

### 415 Unsupported Media Type

The request body's Content-Type is not one the endpoint takes. Returns `ErrorEnvelope`.

### 429 Too Many Requests

Too many requests, or no call capacity right now. Retry after the Retry-After delay. Returns `ErrorEnvelope`.

### 500 Internal Server Error

Something went wrong on MoreVoice's side. Retry with the same Idempotency-Key. Returns `ErrorEnvelope`.

### 503 Service Unavailable

A dependency this endpoint needs (a speech or language model, file storage) is temporarily unavailable. Retry later. Returns `ErrorEnvelope`.

## Code samples

**TypeScript**

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const file = await mv.files.create({
	file: {
		content_base64: "JVBERi0xLjQKJcfsj6IK",
		filename: "loa-signed.pdf",
	},
	purpose: "port_document",
});
console.log(file);
```

**Python**

```python
from morevoice import MoreVoice

client = MoreVoice()  # MOREVOICE_API_KEY from the environment

file = client.files.create({
    "file": {
        "content_base64": "JVBERi0xLjQKJcfsj6IK",
        "filename": "loa-signed.pdf",
    },
    "purpose": "port_document",
})
print(file)
```

**cURL**

```sh
curl -X POST https://api.morevoice.ai/v1/files \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "file": {
    "content_base64": "JVBERi0xLjQKJcfsj6IK",
    "filename": "loa-signed.pdf"
  },
  "purpose": "port_document"
}'
```
