Controlling View Source Redirects

When developers integrate your licensed content with AI tools — chat agents like ChatGPT, Claude, and Perplexity, or their own search experiences — Cashmere's search endpoint returns a view_source_url for each result. End users click these links to view the source of the content the AI used.

Cashmere lets you, the publisher, control exactly where those clicks land. This guide explains the three integration points where you can configure that destination, the three view source actions available, and how to use per-license metadata to send each licensee's users to their own portal or LMS.

How a click on view_source_url is resolved

When a user clicks a view_source_url, Cashmere looks at the user's license against the collection that contains the book and chooses a destination by walking through the configured view source actions in order. The first action that produces a URL wins.

There are three places you can set or override this behavior:

  1. At ingest time — set source_url (and optionally external_id) on the omnipub.
  2. At the collection level — set view_actions on the collection.
  3. At the license level — set view_actions and metadata on the license (highest priority).

License-level view_actions take precedence over collection-level view_actions. If neither is set, the user is shown the content on Cashmere.

The three view source actions

1. view_on_cashmere

This is the default behavior. The user is redirected to the Cashmere viewer for the book. Useful for publishers who don't already have a public landing page or website hosting their content. Branding (logos, colors, fonts) is configurable per collection — see the publisher branding settings in the Console.

2. pub_source_url

The user is redirected to the omnipub's source_url if one is set on the omnipub at ingest time. If no source_url is available on the omnipub, Cashmere falls back to showing the content on Cashmere.

Use this when each book already has a stable public URL (a marketing page, an article on your site, a product page). The URL is fixed per omnipub and is the same for every licensee. You can pair this with an external_id on the omnipub if you want a stable handle for matching it back to your own systems.

3. pub_source_url_template

The user is redirected to a URL constructed from a template at click time. This is the most flexible action — you can interpolate book metadata, per-license metadata, and request-time variables to build the destination dynamically.

You provide a template string like:

https://{{ license.metadata.portal }}/article/{{ uuid }}?title={{ title|urlencode }}

Cashmere renders the template with the variables described below.

Variables available in templates

The same variables are available whether the template is configured at the collection level or the license level.

Book variables (resolved from the omnipub being viewed):

Variable Description
uuid Cashmere omnipub UUID
external_id The publisher-provided external ID, if set at ingest time
title Omnipub title
subtitle Omnipub subtitle, if any
creation_date Original creation date
updated_date Last updated date
publisher Publisher name
source_url The omnipub's source_url, if set
section_block_uuid The section block UUID when a click targets a specific section
block_uuids Comma-separated block UUIDs from the search result's link. Parts that are not UUIDs are dropped.

Custom ID variables (your own IDs, stored on the omnipub):

Variable Description
custom_id.<name> The value of the omnipub's custom ID called <name>. Empty if the omnipub has no custom ID of that name.

See Using your own IDs in templates.

License variables (resolved from the licensee's approved license, when one exists):

Variable Description
license.metadata.<key> Any key you stored under the license's metadata field

Note: license.metadata.<key> is available even when the active view_actions come from the collection, as long as the licensee has an approved license. This means you can keep one collection-level template and let per-license metadata customize each licensee's destination.

Allowed template syntax

Templates use a restricted templating syntax. Only the following are allowed:

  • Tags: {% if %} ... {% endif %}
  • Filters: urlencode, lower, upper, default

Other tags, filters, and template features are rejected at save time.

Per-license metadata

Each license has a metadata JSON field (publisher-controlled) that you can read inside templates as license.metadata.<key>. Combined with pub_source_url_template, this lets you keep one collection-level template and route each licensee's users to a different destination.

You can set metadata:

  • At grant time — pass metadata on POST /api/v2/licenses
  • After grant — PUT /api/v2/licenses/{id}/metadata (replaces the entire object; pass {} to clear)

The same pattern applies for view actions:

  • At grant time — pass view_actions on POST /api/v2/licenses
  • After grant — PUT /api/v2/licenses/{id}/view-actions

Using your own IDs in templates

Your site can address a book by an ID that Cashmere does not know, such as a URL slug. Store that ID on the omnipub as a custom ID, and the template can use it.

A custom ID works like the omnipub's external_id, but an omnipub can have many. Each custom ID has a name and a value, and each name on an omnipub is different.

  • A name is 1-40 characters of a-z, 0-9 and _, and starts with a letter.
  • A value is a non-empty string of at most 500 characters, with no control characters such as newlines. Leading and trailing spaces are trimmed.
  • To remove a name, send null as its value, not "".
  • An omnipub can hold at most 50 names, counting those it shares with other omnipubs (see below), and one request can set at most 50.

Set custom IDs at ingest time

Pass custom_ids inside metadata on POST /api/v2/omnipub:

curl -X POST "https://cashmere.io/api/v2/omnipub" \
  -H "Authorization: Bearer YOUR_PUBLISHER_API_KEY" \
  -F "file_url=https://example.com/articles/the-leadership-gap.html" \
  -F "external_id=R2104C" \
  -F 'metadata={"custom_ids": {"hbr_slug": "the-leadership-gap"}}'

Change custom IDs later

Send custom_ids to PUT /api/v2/omnipub/{omnipub_uuid}/metadata. You do not need to upload the publication again.

curl -X PUT "https://cashmere.io/api/v2/omnipub/6f1c2a9e3b7d4c8e9a512d4f8b0c7e13/metadata" \
  -H "Authorization: Bearer YOUR_PUBLISHER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"custom_ids": {"hbr_slug": "closing-the-leadership-gap", "old_code": null}}'
  • Each name you send replaces that name's current value.
  • A null value removes that name.
  • Names you leave out keep their values.

Each change is stored as a metadata record of type custom_id. To see an omnipub's custom ID names and their history, call GET /api/v2/omnipub/{omnipub_uuid}/metadata-records. To read a value, call GET /api/v2/metadata-records/{record_id} and use payload.custom_id.value.

Custom IDs follow the external ID

Custom IDs follow the omnipub's external_id. Every omnipub in your organization with the same external_id shares one set of custom IDs. When you deprecate an omnipub and ingest a replacement with the same external_id, the replacement keeps its custom IDs, and you do not need to send them again. A change on any of these omnipubs applies to all of them. That includes omnipubs that are live at the same time: if two live omnipubs share an external_id, they share their custom IDs too.

An omnipub without an external_id keeps its own custom IDs. If you replace one, send its custom IDs again on the new omnipub.

If Cashmere rejects a new omnipub as a duplicate of one you already have, its custom IDs are copied to the existing omnipub, unless that would take the existing omnipub over 50 names; then none are copied.

Use a custom ID in a template

https://hbr.org/{{ custom_id.hbr_slug|urlencode }}

Add |urlencode whenever a value can hold characters other than ASCII letters, digits, -, _, ., ~ and /. It percent-encodes the rest, so a value a&b's becomes a%26b%27s. Without it, a value is copied into the URL as it is, so a space, & or ? changes what the URL means, and non-ASCII text breaks the redirect.

If an omnipub has no custom ID of that name, {{ custom_id.<name> }} renders as an empty string. Use {% if %} to fall back to another URL:

{% if custom_id.hbr_slug %}https://hbr.org/{{ custom_id.hbr_slug|urlencode }}{% else %}https://hbr.org/search?term={{ title|urlencode }}{% endif %}

Worked example: redirecting to your own article pages by slug

Northwind Review publishes articles on https://northwind.example. Its site addresses each article by a slug, such as https://northwind.example/articles/the-quiet-merger. Cashmere does not know these slugs, so Northwind stores each one on its omnipub as a custom ID called site_slug.

Step 1 — Add the custom ID at ingest

Send site_slug in custom_ids inside metadata when you create the omnipub. Set an external_id too, so the slug carries over if you replace the omnipub later.

curl -X POST "https://cashmere.io/api/v2/omnipub" \
  -H "Authorization: Bearer YOUR_PUBLISHER_API_KEY" \
  -F "file_url=https://northwind.example/feeds/the-quiet-merger.html" \
  -F "external_id=NW-2026-0412" \
  -F 'metadata={"custom_ids": {"site_slug": "the-quiet-merger"}}'

Step 2 — Backfill your existing omnipubs

For each omnipub you already sent, add its slug with PUT /api/v2/omnipub/{omnipub_uuid}/metadata. This does not upload or reparse the publication.

curl -X PUT "https://cashmere.io/api/v2/omnipub/6f1c2a9e3b7d4c8e9a512d4f8b0c7e13/metadata" \
  -H "Authorization: Bearer YOUR_PUBLISHER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"custom_ids": {"site_slug": "the-quiet-merger"}}'

To add a second custom ID later, send only the new name. Names you leave out keep their values, so site_slug stays:

curl -X PUT "https://cashmere.io/api/v2/omnipub/6f1c2a9e3b7d4c8e9a512d4f8b0c7e13/metadata" \
  -H "Authorization: Bearer YOUR_PUBLISHER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"custom_ids": {"legacy_id": "A-77310"}}'

Step 3 — Set the template on the collection

In the Console, open the collection, and go to View Source Actions. Put Publisher Source URL Template first in the action order, and enter this template:

{% if custom_id.site_slug %}https://northwind.example/articles/{{ custom_id.site_slug|urlencode }}{% else %}https://northwind.example/search?q={{ title|urlencode }}{% endif %}

|urlencode keeps the slug safe in the URL. The {% else %} branch sends readers to a search for the title when an omnipub has no site_slug yet.

Step 4 — Check that it works

  1. Use a licensee's API key to call /api/v2/search for content in the collection.
  2. Take the view_source_url from a result for an omnipub that has a site_slug, and follow it:

bash curl -Ls -o /dev/null -w '%{url_effective}\n' "<view_source_url>"

  1. Confirm the result is https://northwind.example/articles/the-quiet-merger.
  2. Repeat with an omnipub that has no site_slug. Confirm the result is the search URL.

Worked example: routing each licensee to their own portal

You publish a blog and license its archive to several enterprise customers (Acme, Globex, Initech). Each customer hosts their own learning management system (LMS) where their employees consume the content. When an Acme employee asks an AI agent a question, sees a citation to one of your articles, and clicks the source link, you want them to land on the Acme LMS — not on Cashmere, and not on Globex's portal.

Step 1 — Set a collection-level template

On your blog collection, configure the view_actions:

[
  {
    "action": "pub_source_url_template",
    "source_url_template": "https://{{ license.metadata.portal }}/lms/article/{{ uuid }}?title={{ title|urlencode }}"
  }
]

This single template covers every licensee.

Step 2 — Stash per-licensee metadata on each license

When granting the license to Acme:

curl -X POST "https://cashmere.io/api/v2/licenses" \
  -H "Authorization: Bearer YOUR_PUBLISHER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "target_email": "licensing-admin@acme.example.com",
    "collection_ids": [42],
    "metadata": {"portal": "learn.acme.example.com"}
  }'

When granting to Globex:

curl -X POST "https://cashmere.io/api/v2/licenses" \
  -H "Authorization: Bearer YOUR_PUBLISHER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "target_email": "licensing-admin@globex.example.com",
    "collection_ids": [42],
    "metadata": {"portal": "kb.globex.example.com"}
  }'

If you need to update metadata on an existing license later, PUT to /api/v2/licenses/{license_id}/metadata:

curl -X PUT "https://cashmere.io/api/v2/licenses/107/metadata" \
  -H "Authorization: Bearer YOUR_PUBLISHER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"metadata": {"portal": "new-portal.acme.example.com"}}'

Step 3 — Done

When an Acme user clicks a view_source_url, Cashmere renders the collection's template with that user's license metadata and redirects to:

https://learn.acme.example.com/lms/article/<book-uuid>?title=...

When a Globex user clicks the same kind of link on a search hit for the same article, they are redirected to:

https://kb.globex.example.com/lms/article/<book-uuid>?title=...

If you ever need a one-off override for a specific licensee — say, Initech wants every link to land on a single dashboard URL regardless of which article was searched — you can set view_actions directly on that license, and it will take precedence over the collection's template for that licensee only.

Verifying your configuration

The simplest way to verify a template is to perform an end-to-end test:

  1. Issue (or update) a license with the metadata you want to test.
  2. Use the licensee's API key to call /api/v2/search for content in the licensed collection.
  3. Take the view_source_url from a result and follow it (e.g. curl -Ls -o /dev/null -w '%{url_effective}\n' <url>).
  4. Confirm the resolved URL matches what you expected.

You can also see the configured metadata and view actions on the license's detail page in the Console (visible to the publisher only).

Summary

  • Three integration points: omnipub source_url, collection view_actions, license view_actions + metadata.
  • Store your own IDs on an omnipub as custom_ids and use them in templates as custom_id.<name>. They follow the omnipub's external_id across deprecate-and-replace.
  • License-level overrides collection-level; if nothing is set, users see the content on Cashmere.
  • Use pub_source_url_template plus per-license metadata to send each licensee's users to their own destination from a single collection-level template.