# Share links

> Share one result, a generation session or a project by a view-only link with the Nodaro API, read what the link shows, and get a preview card for social posts.

Source: https://nodaro.ai/docs/developers/api/share-links

A **share link** is an unguessable, view-only link to one of your results (a job), a generation session or a project. Anyone signed in can make one, and anyone can open it, with no account. The link shows the results, the prompt as it was written, the model and the settings. With **allow copy** on, it also hands out the reference files the result was made from.

Each item has one link. Turning the link off makes it answer `404`. Turning it on again brings back the **same** token, so a link you handed out before works again.

## Endpoints
| Method | Path | What it does |
| --- | --- | --- |
| `GET` | `/v1/shares?kind=&targetId=` | Your link for one of your items. |
| `PUT` | `/v1/shares` | Turn the link of one of your items on or off. |
| `GET` | `/v1/public/shares/:token` | What the link shows. No credential needed. |
| `GET` | `/v1/public/shares/:token/items` | The results of a shared session or project, a page at a time. No credential needed. |

## Turn a link on or off
**curl**

```bash
# Turn the link of one of your jobs on.
TOKEN=$(curl -s -X PUT "https://app.nodaro.ai/v1/shares" \
  -H "Authorization: Bearer $NODARO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind":"job","targetId":"<job-id>","shared":true}' | jq -r .data.token)

# What the link shows. No credential needed.
curl -s "https://app.nodaro.ai/v1/public/shares/$TOKEN"
```

**TypeScript SDK**

```ts
const share = await client.shares.set({ kind: "job", targetId: jobId, shared: true })
const shown = await client.shares.getPublic(share.token)
```

`PUT /v1/shares` takes this body:

| Prop | Type | Description |
| --- | --- | --- |
| `kind` (required) | `"job" \| "session" \| "project"` | What you share: one result, a generation session or a project. |
| `targetId` (required) | `string` | The id of the job, session or project. It must be yours. |
| `shared` (required) | `boolean` | true turns the link on. false turns it off. |
| `allowCopy` | `boolean` | true also hands out the reference files the result was made from. Left out, the link keeps its current value, which is false on a new link. |
| `locale` | `string` | The interface language the link is shared in, for example en, de, es, he, ja, ko or pt-BR. The link's preview card is written in it. he-IL reads as he. Left out, the link keeps its language, which is English on a new link. An unknown id is ignored, never a 400. |

The first call makes the link. Later calls keep its token. The answer is `{ data: Share }`. Turning a link off always works. Turning a link on answers `422 share_not_allowed`, with a `reason`, when the item cannot be shared now. See [What a link never shows](#never-shown). The route answers `404` when the item is not yours.

`GET /v1/shares?kind=&targetId=` reads your link for one of your items. It answers `{ data: Share | null }`, with `null` when the item was never shared. It answers `404` when the item is not yours.

A `Share` is `{ token, kind, targetId, shared, allowCopy, createdAt, updatedAt, locale }`. `locale` is `null` for English, and on a server from before the link kept its language.

## What a link shows
`GET /v1/public/shares/:token` answers `{ data: { kind, allowCopy, job? | session? | project? } }`. Exactly one of `job`, `session` or `project` is there, as `kind` says.

A shared **job** is `{ id, type, mediaKind, outputUrl, outputUrls?, width?, height?, durationSec?, title, songTitle?, toolName, coverUrl, createdAt, prompt, displayPrompt, negativePrompt?, model, settings, references?, trend? }`:

- `toolName` is what a person calls the tool that made the result, for example `"Song Mashup"`, `"Text to Speech"` or `"Image to Video"`. It is never a model's name. It is `null` for a tool with no public name.
- `songTitle` is a song's own title, of the take that `outputUrl` names, when the song has one.
- `coverUrl` is the result's picture: the owner's cover, else the art made with the result, else `null`. See [Set a job's cover](https://nodaro.ai/docs/developers/api/jobs#cover).
- `prompt` is the prompt as it was written, exactly as sent. When your app sent a `userPrompt`, the link shows that prompt.
- `displayPrompt` is the same prompt as a person reads it. Each reference token becomes the name on its pill. `@<slug>:<N>`, with its role, variant or `~lock`, becomes the name of the reference it names. When no name is known, the slug is made readable: `@image-1:1` becomes `@Image 1`. `{video:N:label}`, `{audio:N:label}` and `{image:N:label}` become `@label`. Only names come from the references, never an address or an id. Both `prompt` and `displayPrompt` are `null` for a trend run.
- `model` is the public model id and its name. It is `null` for a model that the public catalog does not list.
- `settings` is the job's input without the prompt and model fields, and without anything internal: ids of rows, credits and prices, webhooks, tokens, storage keys and error text.
- `settings` never holds a value that is an address or an id, whatever the field is called. That covers a link, a uuid, a path or storage key, a host or file name, an email, and a long id or hash. A nested object that held one, such as an image and its role, is left out whole.
- `references` is a list of `{ url, kind }`, at most 32. It is there only when the link allows copying. It holds https files only, never an address that carries a signature, a token, a key or a password.
- A **trend run** shows as `trend: { slug, name }`, with `prompt: null`, empty `settings` and no `references`. The trend's recipe belongs to the platform.

A shared **session** is `{ title, tool, createdAt, itemCount }`.

A shared **project** is `{ name, sessions: [{ id, title, tool, itemCount, coverUrl }] }`. It lists the project's personal, unarchived sessions that show at least one result, most recently active first, at most 200. `itemCount` counts only what the link shows. `coverUrl` is the session's cover when the cover is shown, else its newest shown image.

## List the results of a session or a project
`GET /v1/public/shares/:token/items` lists the results of a shared session, newest first. It answers `{ data: SharedJob[], nextCursor }`, where each item has the shape of a shared job.

| Query | Meaning |
| --- | --- |
| `sessionId` | Required for a shared project: one of the sessions the link lists. A shared project without it answers `400`. |
| `limit` | Page size, 1 to 100. The default is 50. |
| `cursor` | The `nextCursor` of the previous page. |

A page may hold fewer results than `limit`. Follow `nextCursor` until it is `null`.

A result the link may not show is skipped, and the page reads on to fill `limit`. `nextCursor` is always the position of the last result shown, never of one left out. Walking the pages therefore reveals nothing about the hidden results.

## What a link never shows
A link shows only finished results of its owner that the platform would let anyone see. The cases below are not shown. `PUT /v1/shares` also refuses to turn a link on for them, with `422 share_not_allowed` and this `reason`:

| `reason` | Why |
| --- | --- |
| `not_completed` | The job has not finished, or it failed or was cancelled. |
| `no_media` | The job made no image, video or sound. |
| `private_output` | The result is kept private: it was made from private inputs, it is a preview render, or it was made in a workspace. |
| `content_filtered` | Its prompt or name trips the content filter that keeps work out of the public gallery. |
| `restricted` | An administrator restricted it. |
| `workspace` | It is a session or project of a workspace. Work in a workspace is never public. |
| `sharing_disabled` | This deployment does not allow public work, so no link opens there. |

A link also never shows a job in the Trash, an item removed from its session, a step of a larger run, or a deleted session or project. Nothing of a blocked account is shown.

All of this is decided again on every read. A result that is moved to the Trash or restricted after it was shared stops showing at once. Its link answers `404`, and a session's link simply stops listing it.

A link to a job you moved to the Trash keeps its state. `GET /v1/shares` still reads it, and `PUT /v1/shares` with `shared: false` turns it off, so the link does not come back on when you restore the job. The link cannot be turned on while the job is in the Trash.

A session that is archived still opens through its own link. A shared project lists only its unarchived sessions.

## The share card for link previews
A link pasted on a social network or in a chat shows a preview. The preview is read from the HTML of the link's address, with no script run. The address to share is the **share card**:

```text
https://nodaro.ai/s/<token>
```

The card answers `200 text/html`, a small page. Its tags come in the first bytes of its `<head>`, right after the charset and the `<title>`:

- `og:title`, `og:description`, and `og:image` with `og:image:secure_url`, `og:image:type`, `og:image:width` and `og:image:height` when they are known, and `og:image:alt`.
- `og:type` (`video.other` for a video, else `website`), `og:site_name` (`Nodaro`) and `og:locale`.
- `og:url` and `<link rel="canonical">`, both the card's own address.
- `twitter:card` (`summary_large_image`), `twitter:title`, `twitter:description`, `twitter:image` and `twitter:image:alt`.
- For a video, `og:video`, with its `secure_url`, its `type`, and its width and height when they are known.
- For a sound, `og:audio`, with its `secure_url` and its `type`.

The video and sound tags are written only when the file is on Nodaro's own storage.

### The card's title and description
The title is the result's own name, then the tool that made it: `Lady's on the Loose · Song Mashup`. The name is chosen in this order:

1. The name its owner gave the result.
2. Its trend's name. A trend run is named by its trend, never by a prompt.
3. The song's own title (`songTitle`).
4. The start of its prompt as a person reads it (`displayPrompt`): `@Maya`, never `@maya:1`.

The tool is `toolName`. A shared session or project is named by its title or name.

The description is one line that says what the item is and that it was made with Nodaro. For example: "A song made with Nodaro", "A video made with Nodaro", "3 results made with Nodaro" or "Made with the Office Dance trend on Nodaro". The line is written in the language the link was shared in (`locale`). The card speaks English, German, Spanish, Hebrew, Japanese, Korean and Portuguese, and any other language reads as English. The page's `lang`, `dir="rtl"` for Hebrew, and `og:locale` follow the same language.

### The card's picture
The picture is always on Nodaro's own storage. It is a 1200×630 JPEG, under 300 KB, made for the link:

| Item | Picture |
| --- | --- |
| An image | The image whole, over a blurred, darkened fill of itself. |
| A video | Its poster, else its first frame, with a play badge. |
| A song or a voice | Its art, that is the result's cover, else the Nodaro tile, with a play badge and its own name drawn beside it. |
| A session or a project | A grid of the pictures of its first results, up to four. |

The name on a song or voice picture is drawn only when every character can be drawn: Latin, Greek, Cyrillic and Hebrew, which reads right to left. For any other name, the picture has no text.

The picture is made once, when the link is turned on. It is made again only when what it shows changes, for example a renamed result or a new cover. Each version has its own address.

A card read before its picture is ready shows the result's own picture when that picture is on Nodaro's storage, else the Nodaro card. Such a card may be cached for one minute only (`Cache-Control: public, max-age=60`). A card never hands out the reference files, whatever the link allows.

### Where the card sends people
The card sends people on at once to the page that shows the link, `https://nodaro.ai/shared/<token>`. It does this with a `<meta http-equiv="refresh">`, a one-line script and a plain link.

Every value on the card is HTML-escaped, and only https addresses are written. The card's `Content-Security-Policy` allows that one script and nothing else. The card says `noindex`, in an `X-Robots-Tag` header and a robots meta tag.

A link that is unknown, turned off, or whose item is gone or may not be shown answers a `404` page. That page says nothing about any content.

On a self-hosted install, the share site serves the card and the page. It is set in the install's configuration. See [Configuration](https://nodaro.ai/docs/self-hosting/configuration#instance).

## Rate limits and caching
| Read | Limit per network | Caching |
| --- | --- | --- |
| `GET /v1/public/shares/:token` | 60 a minute | Never cached (`Cache-Control: no-store`) |
| `GET /v1/public/shares/:token/items` | 120 a minute | Never cached (`Cache-Control: no-store`) |
| The share card, `/s/<token>` | 120 a minute | Up to 5 minutes (`Cache-Control: public, max-age=300`), or 1 minute until its picture is ready |

A read over its limit answers `429 rate_limit_exceeded`. Because the card may be cached, a link you turn off stops previewing within minutes. The card's `404` page is never cached. See [Rate limits](https://nodaro.ai/docs/developers/api/rate-limits).

## Scopes for OAuth apps
| Route | Scope |
| --- | --- |
| `GET /v1/shares` | `jobs:read` |
| `PUT /v1/shares` | Both `assets:write` and `jobs:read`, because the token it hands back reads what the link shows |
| `GET /v1/public/shares/:token` and its items | None |

A personal API token that is limited to some workflows cannot reach `GET /v1/shares` or `PUT /v1/shares`. See [OAuth](https://nodaro.ai/docs/developers/oauth#scopes).

## From the SDK
`client.shares` has `get`, `set`, `getPublic` and `publicItems`. `getPublic` and `publicItems` work signed out. See [Share links in the SDK](https://nodaro.ai/docs/developers/sdk/share-links).

## Frequently asked questions

### How do I share a Nodaro result by link through the API?

Send PUT /v1/shares with kind job, the job's id as targetId and shared true. The answer holds the link's token. Anyone can then read what the link shows with GET /v1/public/shares/:token, with no credential.

### What does a Nodaro share link show?

The finished result or results, the prompt as it was written, the model and the settings. It never shows an address or an id from the settings. With allowCopy on, it also lists the reference files the result was made from.

### What happens when I turn a share link off and on again?

Turned off, the link answers 404. Turned on again, the same token comes back, so a link you handed out before works again. Each item has one link.

### Why does PUT /v1/shares answer 422 share_not_allowed?

The item cannot be shared now. The reason field says why, for example not_completed for a job that has not finished, or workspace for work in a workspace. No link was made or turned on.

### Which address should I post on a social network?

Post the share card, https://nodaro.ai/s/ followed by the token. Its HTML carries the Open Graph and Twitter tags for the preview, and it sends people on to the page that shows the link.
