# File routes: edit, generate

URL: /code/api/file/verbs · Id: `page:code/api/file/verbs`

> The File Verbs edit, generate as api.sb routes, with inputs, result, refusals and an example.

Reference for [File](/business/nouns/file), one group of [File routes](/code/api/file).

### File.edit
Edit makes a new File from an existing one by instruction, such as upscaling or animating a still, and leaves the source unchanged. [Verb page](/business/nouns/file/edit?interface=api).

```text
POST /{namespace}/files/{file}/edit
```

Path: `file`. Body, as JSON: the other inputs. Emits [`File.edited`](/business/events/File.edited).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | [File](/business/nouns/file) | Yes | The source File. |
| `instruction` | `text` | Yes | What to change. |
| `references` | list of [File](/business/nouns/file) | No | Further Files the edit follows. |
| `format` | `json` | No | Aspect ratio, resolution, duration and file type of the result. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | [File](/business/nouns/file) | Yes | The new File, which records its source. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/files/file_V1AuhyCTsH/edit \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"instruction":"Example instruction"}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "file": {
    "$id": "https://api.sb/leaseline.app/files/file_V1AuhyCTsH",
    "$type": "File",
    "contentType": "Example content type",
    "size": 1
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "File.edit",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

### File.generate
Generate makes an image, video, speech or music File from a prompt and reference Files, and records how it was made. [Verb page](/business/nouns/file/generate?interface=api).

```text
POST /{namespace}/files/generate
```

Body, as JSON: the inputs. Emits [`File.generated`](/business/events/File.generated).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `kind` | `string` | Yes | What to make. |
| `prompt` | `text` | Yes | What to make, or for `speech` the text to speak. |
| `references` | list of [File](/business/nouns/file) | No | Files the output follows, such as a product photo or a first frame. |
| `voice` | [Voice](/business/nouns/voice) | No | The Voice that speaks, for `speech`. |
| `format` | `json` | No | Aspect ratio, resolution, duration and file type. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | [File](/business/nouns/file) | Yes | The generated File, its bytes in Storage and its provenance recorded. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/files/generate \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind":"image","prompt":"Example prompt"}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "file": {
    "$id": "https://api.sb/leaseline.app/files/file_V1AuhyCTsH",
    "$type": "File",
    "contentType": "Example content type",
    "size": 1
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "File.generate",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```