---
search:
  tags:
    - Assets
    - POST
seo:
  description: >-
    Creates an Asset in one of two ways. The Content-Type of the request picks
    one. Reference for the POST /library/assets endpoint in the AdCrunch API.
sidebar:
  label: Create an Asset from raw bytes
  badge: POST
title: Create an Asset from raw bytes
type: openapi-operation
---
Creates an Asset in one of two ways. The `Content-Type` of the request picks one.

**Raw bytes.** The body is the file. AdCrunch answers `201` with a `ready` Asset. Do not use `multipart/form-data`.

```
curl --data-binary @ad.png \
  -H "Authorization: Bearer $ADCRUNCH_API_KEY" \
  "https://api.adcrunch.dev/library/assets?filename=ad.png"
```

The bytes stream into storage. AdCrunch identifies the type from the bytes, and the `Content-Type` is only a hint. A file that AdCrunch refuses leaves no object and no Asset.

The request needs a `Content-Length`. A body with no length answers `411`.

**Size.** This route takes a body up to 95 MB. Over that, it answers `413` with `error` set to `use_upload_url`: reserve an upload with `POST /library/assets/uploads`, and `PUT` the file to the URL. A body over the limit of the Cloudflare plan of the domain, 100 MB at the lowest, never reaches AdCrunch. Cloudflare refuses it at the edge with its own `413` page, with no `use_upload_url`. Send a large video to `POST /library/assets/uploads`.

**Import from a URL.** The JSON body needs a `Content-Length` and is at most 8 KB. Send `Content-Type: application/json` with `{ "sourceUrl": "https://...", "name": "..." }`. `sourceUrl` must be an `https` URL on port 443, else the answer is `400` with `error` set to `invalid_url`. Its host must be a public name: an IP address, a local or private host, or an AdCrunch domain (`adcrunch.dev` and its subdomains) answers `400` with `error` set to `source_not_allowed`. AdCrunch answers `202` with a `pending` Asset, and a Workflow fetches the file. Poll `GET /library/assets/{id}` until `status` is `ready` or `failed`. A `failed` Asset has a `failureCode`: `source_unreachable` (the source did not answer, answered with an error, or sent the file in part), `source_length_unknown` (the source sent no `Content-Length`), `too_large`, `unsupported_type` or `unreadable`. The import does not follow a redirect to a URL that is not `https`.

```
curl -X POST \
  -H "Authorization: Bearer $ADCRUNCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"sourceUrl":"https://example.com/ad.png"}' \
  "https://api.adcrunch.dev/library/assets"
```

`POST /library/assets`

**Request body** (`application/json`, required)

The raw bytes of the file with any \`Content-Type\` except \`application/json\`, or a JSON import \`{ sourceUrl, name? }\`.

- `name` (string) — The name to show in place of the filename.
- `sourceUrl` (string, required) — An \`https\` URL of an image or a video.

Request body example:

```json
{
  "name": "string",
  "sourceUrl": "https://example.com/ad.png"
}
```

**Responses**

- `201` — The stored Asset, already \`ready\`.
- `202` — The import started. The Asset is \`pending\`. Poll \`GET /library/assets/{id}\` until it is \`ready\` or \`failed\`.
- `400` — The request does not match the schema of this operation: a field is missing or has the wrong type, or the body is not valid JSON. \`error\` is \`invalid\_request\`, and \`issues\` names each field. Nothing was changed.
- `401` — No API key, or one that does not resolve. See the security scheme. \`error\` is \`unauthorized\`.
- `402` — The organization has no active subscription. An owner subscribes at \`paywallUrl\`. \`error\` is \`organization\_unentitled\`.
- `403` — The caller does not hold \`library:write\`. \`error\` is \`forbidden\`.
- `411` — The request has no \`Content-Length\`. \`error\` is \`length\_required\`. This holds for a raw body and for a JSON body.
- `413` — The body is too large. \`error\` names why: - \`use\_upload\_url\`: the body is over 95 MB. Use \`POST /library/assets/uploads\`. - \`payload\_too\_large\`: the JSON body of an import is over 8 KB. - \`too\_large\`: the file is over the limit for its kind, 30 MB for an image and 4 GB for a video. AdCrunch stored nothing. A body over the limit of the Cloudflare plan of the domain gets a \`413\` from Cloudflare, before AdCrunch runs. That answer has no \`error\` code.
- `415` — AdCrunch refused the file. \`error\` names why: - \`unsupported\_type\`: the bytes are no type that AdCrunch accepts. - \`unreadable\`: the file ends before its header does.

Response example, 201:

```json
{
  "contentHash": "9d2f41b7c6e8a35014f7b2d9c3e6a810",
  "createdAt": 1790000000000,
  "createdBy": "usr_2e5b84",
  "deletedAt": null,
  "durationMs": 15000,
  "failureCode": null,
  "failureReason": null,
  "filename": "spring-sale.mp4",
  "height": 1920,
  "id": "ast_7c1e9a",
  "key": "org_3a7f10/ast_7c1e9a",
  "kind": "video",
  "mimeType": "video/mp4",
  "name": null,
  "organizationId": "org_3a7f10",
  "sizeBytes": 24117248,
  "status": "ready",
  "updatedAt": 1790000120000,
  "width": 1080
}
```

Response example, 202:

```json
{
  "contentHash": "9d2f41b7c6e8a35014f7b2d9c3e6a810",
  "createdAt": 1790000000000,
  "createdBy": "usr_2e5b84",
  "deletedAt": null,
  "durationMs": 15000,
  "failureCode": null,
  "failureReason": null,
  "filename": "spring-sale.mp4",
  "height": 1920,
  "id": "ast_7c1e9a",
  "key": "org_3a7f10/ast_7c1e9a",
  "kind": "video",
  "mimeType": "video/mp4",
  "name": null,
  "organizationId": "org_3a7f10",
  "sizeBytes": 24117248,
  "status": "pending",
  "updatedAt": 1790000120000,
  "width": 1080
}
```
