# Quickstart

Sign a first file by sending it from your server with an API key, then check the signed file in Lens Proof Check.

## Before you start

- Sign in to the [developer console](/developers) and start a workspace for 10 test-certificate signatures and an API key. Copy the key when it appears; it is shown only once. If you already belong to a team, ask its admin for a key. See [Authentication](/docs/authentication).
- Put the key in an environment variable named `LENS_PROOF_SIGN_API_KEY` on your server. Never put the key in browser code or in a repository.
- Choose a file of a [supported media type](/docs/media-types) that is at most 10 MB, or at most 30 MB for a video. The samples below sign a JPEG named `photo.jpg`.
- If you want a sample image to test with, download [photo.jpg](/samples/photo.jpg).

## Send the file

Send the file's bytes as the request body, and set `Content-Type` to the file's media type. Do not send a form upload (`multipart/form-data`), a query string, or freeform metadata. Optional AI disclosure headers are listed in [Headers](/docs/reference#headers).

To sign your own file, change only `FILE`, for example `FILE=/path/to/IT.png`. The curl sample sets `Content-Type` from the file's bytes with `file --mime-type`, because the API checks the bytes, not the name: a JPEG saved as `IT.png` is still a JPEG. The signed file is saved as `signed-` followed by your file's name. Slim server images such as Alpine or Debian slim often leave out `file`; the sample then stops with `file: command not found` before it sends anything. Install it (`apk add file` or `apt-get install file`), or replace the `TYPE` line with the type itself, such as `TYPE=image/jpeg &&`. If you write your own command, keep two things:

- Keep the `@` before the path, as in `--data-binary @photo.jpg`. Without it, curl sends the path as text, and the API answers `400` with the code `unrecognized_file`.
- Set `Content-Type` to the type of the file's bytes, not the type its name suggests. If the two disagree, the API answers `415` with the code `type_mismatch`, and the message names the type to send. If `file` prints a type that is not in [Media types](/docs/media-types), the API does not accept the file.

The signed file is always the same type as the file you send. The API does not convert between types. To get another type, convert the file first and then sign it, because converting a signed file breaks its credentials.

```bash title="curl"
FILE=photo.jpg &&
TYPE=$(file --mime-type -b "$FILE") &&
curl https://sign-api.lensproof.app/v1/sign \
  --request POST \
  --header "Authorization: Bearer $LENS_PROOF_SIGN_API_KEY" \
  --header "Content-Type: $TYPE" \
  --data-binary @"$FILE" \
  --fail-with-body \
  --output "signed-$(basename "$FILE")"
```

```js title="Node"
import { readFile, writeFile } from "node:fs/promises";

const response = await fetch("https://sign-api.lensproof.app/v1/sign", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.LENS_PROOF_SIGN_API_KEY}`,
    "Content-Type": "image/jpeg",
  },
  body: await readFile("photo.jpg"),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`Signing failed with ${response.status} ${error.code}: ${error.message}`);
}

await writeFile("signed.jpg", Buffer.from(await response.arrayBuffer()));
```

```python title="Python"
import os
from pathlib import Path

import requests

response = requests.post(
    "https://sign-api.lensproof.app/v1/sign",
    headers={
        "Authorization": f"Bearer {os.environ['LENS_PROOF_SIGN_API_KEY']}",
        "Content-Type": "image/jpeg",
    },
    data=Path("photo.jpg").read_bytes(),
    timeout=120,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"Signing failed with {response.status_code} {error['code']}: {error['message']}")

Path("signed.jpg").write_bytes(response.content)
```

The Node sample is an ES module that needs Node 18 or later, so save it in a file named `sign.mjs`. The Python sample uses the `requests` package. To sign another file with the Node or Python sample, change `photo.jpg`, `image/jpeg`, and `signed.jpg` together. `Content-Type` must be the type of the file's bytes, as listed in [Media types](/docs/media-types).

## Read the response

A `200` response body is the signed file, with the same `Content-Type` that you sent, so save it as it is. Any other status has a JSON body with an error code, for example:

```json
{
  "error": {
    "code": "unauthorized",
    "message": "A valid API key is required."
  }
}
```

With `--fail-with-body`, curl writes the error JSON to `signed-photo.jpg` and exits with code 22, so check the exit code before you use the file. Run `cat signed-photo.jpg` to read the error. [Errors](/docs/errors) lists every code and what to do about it.

## Check the signed file

Open [Lens Proof Check](https://check.lensproof.app) and select the signed file (`signed-photo.jpg` from the curl sample, `signed.jpg` from the Node or Python sample). Check shows the Content Credentials in the file, and it reports signature integrity, signer certificate trust, and timestamp trust as separate results. To check a file from your server without using a signature, send it to [`POST /v1/validate`](/docs/validate) for the crJSON validation report. [Signed output](/docs/output) explains what the file contains.

## Sign AI-generated media

When your backend signs media generated or edited by an AI model, pass the closed-enum disclosure headers or attach a locked AI disclosure policy to the API key in the [developer console](/developers).

```bash
curl https://sign-api.lensproof.app/v1/sign \
  --request POST \
  --header "Authorization: Bearer $LENS_PROOF_SIGN_API_KEY" \
  --header "Content-Type: image/jpeg" \
  --header "X-Lens-AI-Source: trained_algorithmic_media" \
  --header "X-Lens-AI-Oversight: prompt_guided" \
  --data-binary @generated.jpg \
  --fail-with-body \
  --output signed.jpg
```

See [`POST /v1/sign`](/docs/reference#headers) for every supported AI disclosure value and the per-key disclosure policies.
