This is the abridged developer documentation for Cyan
# Introduction
> Add a checkout to your AI agent with one API call, and take your first payment in five minutes.
Cyan is the payment layer for AI agents. Add a checkout to your agent with one API call. Customers pay in the chat, and the money goes straight to your Stripe account. ## Try it out. Refresh[Open in a new tab](https://chat.cyan.cash) [Live demo: a coffee shop's agent that takes payments in the chat](https://chat.cyan.cash) Pay in the demo with a test card: | Card that passes | 4242 4242 4242 4242 | | | ---------------- | ------------------- | - | | Card that fails | 4000 0000 0000 0002 | | | Expiration date | 12 / 34 | | | Security code | 123 | | | ZIP code | 12345 | | ## Take your first payment [Section titled “Take your first payment”](#take-your-first-payment) In about five minutes you’ll create a payment link, pay it with a test card, and watch it turn `paid`. All you need is a Stripe account. 1. **Connect your Stripe account** In the Cyan app, open [**Settings → Connectors**](https://app.cyan.cash/settings?tab=connectors) and select **Connect with Stripe**. Choose the Stripe account your payments should land in. 2. **Get your API key** Open [**API keys**](https://app.cyan.cash/api-keys) and select **Create API key**. Copy the key and keep it somewhere safe: you’ll only see it once.
```bash
export CYAN_API_KEY="cyan_test_..."
```
3. **Create a payment link** Ask for $49 for a logo design. Amounts are in cents, and the `Idempotency-Key` makes a retry return the same link:
```js
const response = await fetch("https://api.cyan.cash/v1/payment-links", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CYAN_API_KEY}`,
"Idempotency-Key": "first-payment",
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 4900,
description: "Logo design",
}),
});
const link = await response.json();
```
You get back the link:
```json
{
"id": "pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"amount": 4900,
"currency": "USD",
"description": "Logo design",
"customer_name": null,
"status": "pending",
"url": "https://pay.cyan.cash/pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"created_at": "2026-12-05T17:40:12.000Z"
}
```
`url` is the checkout. Send it to your customer, or show it in your chat with the widget. 4. **Pay it** Open `url` in your browser and pay with the test card `4242 4242 4242 4242`, any future date and any CVC. 5. **See it paid** Read the link back. Its `status` is now `paid`.
```js
const response = await fetch(`https://api.cyan.cash/v1/payment-links/${link.id}`, {
headers: { Authorization: `Bearer ${process.env.CYAN_API_KEY}` },
});
const current = await response.json();
console.log(current.status); // "paid"
```
The payment is also in the app under [**Transactions**](https://app.cyan.cash/transactions), and in your Stripe Dashboard. ## Build with your agent [Section titled “Build with your agent”](#build-with-your-agent) Paste this into Claude Code, Cursor or any coding agent:
```text
Read https://docs.cyan.cash/llms-full.txt, then add a Cyan checkout to our chat.
```
Or [connect the docs over MCP](/build-with-ai/#connect-the-docs-over-mcp). See [Build with AI](/build-with-ai/) for more. ## Explore [Section titled “Explore”](#explore) [In-chat checkout](/guides/in-chat-checkout/)Show the checkout as a message in your chat. [Payment links](/guides/payment-links/)Send a link to a hosted checkout page. [Customize the checkout](/widget/customize-checkout/)Match the checkout to your product: name, logo, theme and color. [Confirm payments](/guides/confirm-payments/)Know an order is paid before you fulfill it. [Test your integration](/guides/testing/)Use test keys and test cards to try every path before your customers do. [API reference](/reference/authentication/)Three endpoints, authentication and errors.
# Build with AI
> Build your Cyan integration with Claude Code, Cursor or any coding agent, using docs, an OpenAPI spec and an MCP server made for agents.
Cyan’s docs and API are built to work with AI coding agents like Claude Code, Cursor and Codex. Give your agent the docs, and it can write the integration with you. ## Before you start [Section titled “Before you start”](#before-you-start) Two steps need a person. Do them once in the Cyan app: 1. [Connect your Stripe account](https://app.cyan.cash/settings?tab=connectors). 2. [Create an API key](https://app.cyan.cash/api-keys) and put it in your project’s environment as `CYAN_API_KEY`. Keep the key out of the chat. Your agent only needs to know the variable’s name. ## Start with one prompt [Section titled “Start with one prompt”](#start-with-one-prompt) Paste this into your agent:
```text
Read https://docs.cyan.cash/llms-full.txt, then add a Cyan checkout to our chat.
```
## Give your agent the docs [Section titled “Give your agent the docs”](#give-your-agent-the-docs) Every page of these docs is published as plain text, in the formats agents read best. | File | What’s in it | | ------------------------------------ | ----------------------------------------------------------- | | [`/llms.txt`](/llms.txt) | A short description of Cyan, with links to the files below. | | [`/llms-full.txt`](/llms-full.txt) | Every page of these docs in one Markdown file. | | [`/llms-small.txt`](/llms-small.txt) | A trimmed version, for agents with less room. | | [`/openapi.json`](/openapi.json) | The API as an OpenAPI 3.1 document. | ## Connect the docs over MCP [Section titled “Connect the docs over MCP”](#connect-the-docs-over-mcp) With the docs connected as an MCP server, your agent searches them and reads only the pages it needs, instead of loading everything at once. The server is read-only and needs no key.
```text
https://docs.cyan.cash/mcp
```
* Claude Code Run this in your project:
```bash
claude mcp add --transport http cyan-docs https://docs.cyan.cash/mcp
```
* Cursor Add this to `.cursor/mcp.json` in your project:
```json
{
"mcpServers": {
"cyan-docs": {
"url": "https://docs.cyan.cash/mcp"
}
}
}
```
* Other agents Add the server to your agent’s MCP settings as an HTTP server:
```json
{
"mcpServers": {
"cyan-docs": {
"type": "http",
"url": "https://docs.cyan.cash/mcp"
}
}
}
```
Your agent gets three tools: | Tool | What it does | | ------------- | -------------------------------------------------- | | `search_docs` | Finds the pages that match a question. | | `read_page` | Returns one page as Markdown, or the OpenAPI spec. | | `list_pages` | Lists every page with a one-line description. |
# Apple Pay
> Let customers pay with Apple Pay, in your chat and on a payment link.
Apple Pay lets your customer pay with a card they’ve already saved on their device: no typing, one confirmation. The button appears under **Pay** whenever their browser supports it. | Checkout | Apple Pay | Setup | | --------------------------------------------- | --------- | ------------------------------ | | [Payment link](/guides/payment-links/) | Yes | None. It works out of the box. | | [In-chat checkout](/guides/in-chat-checkout/) | Yes | Add your site’s domain, once. | ## Turn on Apple Pay in your chat [Section titled “Turn on Apple Pay in your chat”](#turn-on-apple-pay-in-your-chat) Apple Pay only appears on sites that are registered for it. Tell Cyan where your chat lives, and Cyan registers the domain with your Stripe account for you. 1. In the Cyan app, open [**Widget**](https://app.cyan.cash/widget). 2. Under **Enable Apple Pay**, enter the domain your chat is on, such as `shop.example.com`. 3. Select **Save**. When the card shows **Enabled**, you’re done. There’s no code to change. The checkout starts showing Apple Pay on its own. New links’ `url` ends in `?wallets=apple_pay`, which holds room for the button so the card doesn’t shift as it loads: pass the `url` to `Cyan.mount` as you got it. A few things to know: * Enter the exact domain your chat is served from. `example.com` and `shop.example.com` count as different domains. * You can register one domain per business. Saving a new one replaces it. * An admin of the business has to save the domain. * Apple Pay needs a public domain, so it won’t appear while you develop on `localhost`. ## How your customer pays [Section titled “How your customer pays”](#how-your-customer-pays) * **Safari:** Apple’s payment sheet opens right in the chat. * **Chrome on a computer:** Apple opens a page with a code to scan with an iPhone. If an Apple Pay payment fails, it’s handled like a declined card: the checkout says so, and your customer can try again or pay by card. Apple Pay never slows down a card payment. The card form is ready first, and the Apple Pay button joins it when it’s available.
# Confirm payments
> Know for certain that an order is paid before you fulfill it.
Before you ship an order, book an appointment or unlock a feature, confirm the payment on your server. The checkout tells your customer the payment went through, and `onPaid` tells your chat page. Both happen in the browser, where a tab can close early and a message can be faked. Your server is where the decision belongs. ## Check the payment link [Section titled “Check the payment link”](#check-the-payment-link) Read the link from your server. Its status is always current.
```js
const response = await fetch(`https://api.cyan.cash/v1/payment-links/${linkId}`, {
headers: { Authorization: `Bearer ${process.env.CYAN_API_KEY}` },
});
const link = await response.json();
const paid = link.status === "paid";
```
```json
{
"id": "pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"amount": 3600,
"currency": "USD",
"status": "paid"
}
```
The response is shortened here. See [the payment link](/reference/payment-link/) for every field. Check the link at these moments: * **When the widget calls `onPaid`.** Your page sends the link’s ID to your server, and your server makes sure the status is `paid`. * **While the checkout is on screen.** Check every few seconds until the link is `paid`. This also catches a payment made in another tab. * **When your agent is asked.** “Did my payment go through?” is one call away. | Status | Meaning | What to do | | ------------ | ------------------------------------- | ------------------------------------------------------- | | `pending` | Not paid yet. | Wait. Your customer can still pay, or try another card. | | `processing` | Accepted, and the bank is confirming. | Wait for `paid`. | | `paid` | The payment succeeded. | Fulfill the order. | | `canceled` | The link was canceled. | Create a new link if your customer still wants to buy. | ## Catch payments after the tab closes [Section titled “Catch payments after the tab closes”](#catch-payments-after-the-tab-closes) Sometimes a customer pays and closes the tab before your page can tell your server. Cyan doesn’t call your server when a payment completes, so keep checking open links from your server:
```js
// Run every minute, for example from a scheduled job.
for (const order of await ordersAwaitingPayment()) {
const response = await fetch(`https://api.cyan.cash/v1/payment-links/${order.linkId}`, {
headers: { Authorization: `Bearer ${process.env.CYAN_API_KEY}` },
});
const link = await response.json();
if (link.status === "paid") await fulfillOrder(order);
if (link.status === "canceled") await closeOrder(order);
}
```
Stop checking a link once it’s `paid` or `canceled`: neither changes again. To stop waiting on a link nobody paid, [cancel it](/reference/cancel-payment-link/). Make fulfillment safe to run twice. Your page and your scheduled check can both report the same payment. ## Refunds and disputes [Section titled “Refunds and disputes”](#refunds-and-disputes) Refund a payment in your Stripe Dashboard, the same way you refund any other. Disputes arrive there too. The Cyan app keeps track for you: [**Transactions**](https://app.cyan.cash/transactions) shows which payments were refunded, in full or in part. In the API, a refunded link keeps the status `paid`.
# Accept a payment in your chat
> Show the Cyan checkout as a message, so your customer pays without leaving the conversation.
The in-chat checkout is a card that appears in the conversation. Your customer enters their card or taps Apple Pay, and the chat carries on. They never leave your product, and card details never touch your page. I'd like to place my order. That comes to $24.00. You can pay right here.  Try it yourself in the [live demo](/). Building this takes three things: a payment link, one script tag, and one function call. ## 1. Create a payment link [Section titled “1. Create a payment link”](#1-create-a-payment-link) On your server, create a payment link:
```js
const response = await fetch("https://api.cyan.cash/v1/payment-links", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CYAN_API_KEY}`,
"Idempotency-Key": order.id,
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 3600,
description: "2 × House Blend, 340 g",
}),
});
const link = await response.json();
```
`amount` is in cents: `3600` is $36. The response includes the link’s `url`. Send it to your chat page along with your agent’s reply, exactly as you received it. ## 2. Add the widget [Section titled “2. Add the widget”](#2-add-the-widget) Load `widget.js` once, then mount the checkout wherever the message should appear:
```html
```
That’s the whole integration. The widget draws the card, loads the payment form, and sizes itself to fit. ### In React [Section titled “In React”](#in-react) Load the script once, mount in an effect, and unmount when the message goes away.
```tsx
import { useEffect, useRef } from "react";
let widget: Promise | undefined;
function loadWidget() {
widget ??= new Promise((resolve, reject) => {
const script = document.createElement("script");
script.src = "https://pay.cyan.cash/v1/widget.js";
script.onload = () => resolve((window as any).Cyan);
script.onerror = () => {
widget = undefined; // let a later mount try again
reject(new Error("Couldn't load the checkout."));
};
document.head.appendChild(script);
});
return widget;
}
export function Checkout({
url,
onPaid,
}: {
url: string;
onPaid: (linkId: string) => void;
}) {
const slot = useRef(null);
useEffect(() => {
let checkout: { unmount(): void } | undefined;
let cancelled = false;
loadWidget()
.then((Cyan) => {
if (cancelled || !slot.current) return;
checkout = Cyan.mount(slot.current, {
url,
onPaid: ({ link }: { link: string }) => onPaid(link),
});
})
.catch(console.error);
return () => {
cancelled = true;
checkout?.unmount();
};
}, [url]);
return ;
}
```
## 3. React to the payment [Section titled “3. React to the payment”](#3-react-to-the-payment) Pass callbacks to `Cyan.mount` to keep your chat in step with the checkout: | Callback | Runs when | | ------------------------ | ------------------------------------------------------- | | `onReady()` | The payment form is ready. | | `onPaid({ link })` | The payment succeeded. `link` is the payment link’s ID. | | `onProcessing({ link })` | The payment was accepted and the bank is confirming it. | | `onError({ message })` | An attempt failed, for example a declined card. | When a card is declined, the checkout shows the reason and your customer can try again right there. You don’t have to handle it. If your customer reloads the chat after paying, mount the same `url` again. The checkout shows the paid state and calls `onPaid` again, so the conversation picks up where it left off. ## Make it fit your chat [Section titled “Make it fit your chat”](#make-it-fit-your-chat) * **Width:** the checkout fills the element you mount it in. Around 428px wide suits most chats. * **Height:** leave it to the widget. It sizes itself, so the messages around it never jump. * **Look:** set a theme, an accent color and a corner style to match your product. See [Customize the checkout](/widget/customize-checkout/). When a message is removed, call `checkout.unmount()`. ## Content Security Policy [Section titled “Content Security Policy”](#content-security-policy) If your site sets a Content Security Policy, allow Cyan in two directives:
```http
Content-Security-Policy: script-src https://pay.cyan.cash; frame-src https://pay.cyan.cash
```
## Next steps [Section titled “Next steps”](#next-steps) * [Turn on Apple Pay](/guides/apple-pay/) in the checkout. * [`Cyan.mount` reference](/widget/mount/) for every option.
# Send a payment link
> Send your customer a link to a checkout page hosted by Cyan.
Every payment link comes with a checkout page hosted by Cyan. Send your customer the link, and they pay in their browser. There is nothing to build. Use it when the conversation happens somewhere you can’t show a checkout: email, SMS, WhatsApp, or a follow-up after a voice call. ## Create and send the link [Section titled “Create and send the link”](#create-and-send-the-link) Create a payment link on your server:
```js
const response = await fetch("https://api.cyan.cash/v1/payment-links", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CYAN_API_KEY}`,
"Idempotency-Key": order.id,
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 12000,
description: "Deposit for March 14",
customer_name: "Ada Lovelace",
}),
});
const link = await response.json();
```
`amount` is in cents: `12000` is $120. The `Idempotency-Key` makes a retry safe: send the same request again and you get the same link, never a second one. The response has a `url`. That’s the checkout page. Have your agent send it to the customer:
```json
{
"id": "pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"url": "https://pay.cyan.cash/pl_019d0a1b2c3d4e5f60718293a4b5c6d7"
}
```
The response is shortened here. See [the payment link](/reference/payment-link/) for every field. ## What your customer sees [Section titled “What your customer sees”](#what-your-customer-sees) A clean checkout page with: * The amount and your description of what it’s for. * “Payment request for Ada Lovelace”, when you pass a `customer_name`. * A card form, and Apple Pay when their device has it. When the payment goes through, the page confirms it and your customer can close the tab. If a card is declined, the page says why and they can try another card. If the link was already paid, the page says so, which means a link can never be paid twice. ## Know when it’s paid [Section titled “Know when it’s paid”](#know-when-its-paid) The page tells your customer the payment went through. To tell your own system, read the link’s status from your server. See [Confirm payments](/guides/confirm-payments/). ## Cancel a link [Section titled “Cancel a link”](#cancel-a-link) A link stays open until it’s paid. To withdraw one, [cancel it](/reference/cancel-payment-link/):
```js
await fetch(`https://api.cyan.cash/v1/payment-links/${link.id}/cancel`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.CYAN_API_KEY}` },
});
```
Your customer then sees “Link expired”. A link that is already paid can’t be canceled: refund it in your Stripe Dashboard instead. ## Prefer to keep customers in your product? [Section titled “Prefer to keep customers in your product?”](#prefer-to-keep-customers-in-your-product) Show the same checkout inside your chat instead. See [Accept a payment in your chat](/guides/in-chat-checkout/).
# Test your integration
> Use test keys and test cards to try every path before your customers do.
Test your whole payment flow without moving any money. Keys that start with `cyan_test_` are test keys: their payments run in Stripe’s sandbox, so you can pay, fail and retry as often as you like. ## Test cards [Section titled “Test cards”](#test-cards) Use any future expiry date, any three-digit CVC and any postal code. | Card number | What happens | | --------------------- | --------------------- | | `4242 4242 4242 4242` | The payment succeeds. | | `4000 0000 0000 0002` | The card is declined. | Stripe’s [testing guide](https://docs.stripe.com/testing) lists more cards, including ones for specific decline reasons. ## A checklist before you launch [Section titled “A checklist before you launch”](#a-checklist-before-you-launch) Run through each of these once: 1. **A payment that succeeds.** The checkout shows “Payment complete”, your server sees the link as `paid`, and the order is fulfilled. 2. **A declined card.** The checkout explains the decline and your customer can try again. Pay with the working card in the same form. 3. **A reload after paying.** Open the same checkout again. It shows the paid state, and nothing is fulfilled a second time. 4. **A closed tab.** Pay with a payment link and close the page straight away. Your server should still find out. See [Confirm payments](/guides/confirm-payments/). 5. **A retried create.** Send the same create request twice with one `Idempotency-Key`. You get the same link both times. 6. **A wrong API key.** Make sure your server handles a `401` cleanly. See [Errors](/reference/errors/). ## See your test payments [Section titled “See your test payments”](#see-your-test-payments) * **In the Cyan app:** [**Overview**](https://app.cyan.cash/) charts your revenue and conversion, and [**Transactions**](https://app.cyan.cash/transactions) lists every payment, with search and filters. * **In Stripe:** each payment appears in your Stripe Dashboard’s sandbox, with the link’s description.
# Authentication
> The API's base URL, your API key and how to send it.
The Cyan API is a JSON API with three endpoints. Every request is authenticated with your API key. ## Base URL [Section titled “Base URL”](#base-url)
```http
https://api.cyan.cash/v1
```
The `/v1` in the path is the version. Changes to it only ever add things, so your integration keeps working. ## Your API key [Section titled “Your API key”](#your-api-key) Send your key as a bearer token on every request:
```js
const response = await fetch(
"https://api.cyan.cash/v1/payment-links/pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
{ headers: { Authorization: `Bearer ${process.env.CYAN_API_KEY}` } },
);
```
## Get a key [Section titled “Get a key”](#get-a-key) Create your key in the Cyan app under [**API keys**](https://app.cyan.cash/api-keys). You’ll need to [connect your Stripe account](https://app.cyan.cash/settings?tab=connectors) first, and be an admin of the business. The key is shown once, when you create it. Store it in your server’s environment or a secrets manager. Each business has one key. If you lose it, or think it has leaked, select **Regenerate** on the same page. The old key stops working immediately, so update your server right away. ## Keep it on your server [Section titled “Keep it on your server”](#keep-it-on-your-server) Your API key can create payments for your business, so treat it like a password: * Call the API only from your backend. * Never put the key in a web page, a mobile app or a public repository. Your chat page doesn’t need the key. It receives a payment link’s `url` from your server, and the customer pays inside Cyan’s checkout. ## Test keys [Section titled “Test keys”](#test-keys) A key that starts with `cyan_test_` is a test key. Its payments run in Stripe’s sandbox and move no money. See [Test your integration](/guides/testing/). ## When authentication fails [Section titled “When authentication fails”](#when-authentication-fails) | Status | `code` | What to do | | ------ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `401` | `api_key_missing` | Send the `Authorization` header. | | `401` | `invalid_api_key` | Check the key. If you regenerated it, use the new one. | | `403` | `provider_not_connected` | Your key works, but your Stripe account isn’t connected. Connect it in the app under [**Settings → Connectors**](https://app.cyan.cash/settings?tab=connectors). | See [Errors](/reference/errors/) for every error code.
# Cancel a payment link
> Cancels a payment link that hasn't been paid, so your customer can no longer pay it.
POST `/v1/payment-links/{id}/cancel` The checkout then shows “Link expired”. Canceling a link that is already canceled returns it unchanged, so a retry is safe. A link that is `processing` or `paid` can’t be canceled. ## Headers [Section titled “Headers”](#headers) `Authorization` string header required Your API key as a bearer token: `Bearer cyan_test_...`. See [Authentication](/reference/authentication/). ## Path [Section titled “Path”](#path) `id` string path required The payment link’s ID. It starts with `pl_`. ## Response [Section titled “Response”](#response) Returns `200` with the [payment link](/reference/payment-link/), now `canceled`. The request has no body. Any other status comes with an error: see [Errors](/reference/errors/). `id` string The link’s ID. `status` string `canceled`. The other fields are the same as on [the payment link](/reference/payment-link/). Cancel a payment link
```js
const response = await fetch(
"https://api.cyan.cash/v1/payment-links/pl_019d0a1b2c3d4e5f60718293a4b5c6d7/cancel",
{
method: "POST",
headers: {
Authorization: "Bearer cyan_test_...",
},
},
);
const link = await response.json();
```
* 200
```json
{
"id": "pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"amount": 4900,
"currency": "USD",
"description": "Logo design",
"customer_name": null,
"status": "canceled",
"url": "https://pay.cyan.cash/pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"created_at": "2026-12-05T17:40:12.000Z"
}
```
* 404
```json
{
"error": {
"code": "payment_link_not_found",
"message": "No payment link with this ID belongs to this business."
}
}
```
* 409
```json
{
"error": {
"code": "payment_link_not_cancelable",
"message": "This payment link is paid or being paid, so it can't be canceled."
}
}
```
* 502
```json
{
"error": {
"code": "provider_unavailable",
"message": "The payment provider couldn't handle the request. Try again."
}
}
```
# Create a payment link
> Creates a payment link for one payment. The payment goes to your own Stripe account.
POST `/v1/payment-links` Your customer can pay by card or Apple Pay. Send the same request again with the same `Idempotency-Key`, and you get the same link back instead of a second one. ## Headers [Section titled “Headers”](#headers) `Authorization` string header required Your API key as a bearer token: `Bearer cyan_test_...`. See [Authentication](/reference/authentication/). `Idempotency-Key` string header required A key you choose for this payment, up to 255 characters, such as your order’s ID. Retrying with the same key and body returns the link the first request made. See [Retries](/reference/errors/#retries). ## Body [Section titled “Body”](#body) `amount` integer required The amount to charge, in the currency’s smallest unit: `4950` is $49.50, and `500` is ¥500. From `1` to `99999999`. `description` string required What the payment is for. Your customer sees it on the checkout. Up to 200 characters. `currency` string default: USD A three-letter ISO 4217 currency code, such as `EUR`. `customer_name` string Your customer’s name. The payment page shows “Payment request for” with this name. Any other field is refused with a `validation_error`. ## Response [Section titled “Response”](#response) Returns `201` with the new [payment link](/reference/payment-link/). A retry with the same `Idempotency-Key` also returns `201`, with the same link. Any other status comes with an error: see [Errors](/reference/errors/). `id` string The link’s ID, such as `pl_019d0a1b2c3d4e5f60718293a4b5c6d7`. `amount` integer The amount in the currency’s smallest unit. `currency` string A three-letter ISO 4217 currency code, in uppercase. `description` string What the payment is for. `customer_name` string or null Your customer’s name, or `null` when you didn’t set one. `status` string Where the payment stands. A new link is `pending`. `url` string The payment page. Send it to your customer, or pass it to [`Cyan.mount`](/widget/mount/) to show the checkout in your chat. Use it as it is, query string included. `created_at` string When the link was created, as an ISO 8601 timestamp in UTC. Create a payment link
```js
const response = await fetch(
"https://api.cyan.cash/v1/payment-links",
{
method: "POST",
headers: {
Authorization: "Bearer cyan_test_...",
"Idempotency-Key": "order-8412",
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 4900,
description: "Logo design",
}),
},
);
const link = await response.json();
```
* 201
```json
{
"id": "pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"amount": 4900,
"currency": "USD",
"description": "Logo design",
"customer_name": null,
"status": "pending",
"url": "https://pay.cyan.cash/pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"created_at": "2026-12-05T17:40:12.000Z"
}
```
* 400
```json
{
"error": {
"code": "validation_error",
"message": "Check the request's fields and try again.",
"params": [
{ "name": "amount", "message": "Must be at least 1" }
]
}
}
```
* 401
```json
{
"error": {
"code": "invalid_api_key",
"message": "This API key isn't valid."
}
}
```
* 403
```json
{
"error": {
"code": "provider_not_connected",
"message": "This business hasn't connected a payment provider. Connect one in the Cyan app."
}
}
```
* 422
```json
{
"error": {
"code": "idempotency_key_mismatch",
"message": "This Idempotency-Key was already used for a different request."
}
}
```
* 502
```json
{
"error": {
"code": "provider_unavailable",
"message": "The payment provider couldn't handle the request. Try again."
}
}
```
# Errors
> The error codes the API returns, what each one means and what to do about it.
Cyan uses standard HTTP status codes. A `2xx` means the request worked. Anything else comes with a JSON body that says what went wrong:
```json
{
"error": {
"code": "validation_error",
"message": "Check the request's fields and try again.",
"params": [
{ "name": "amount", "message": "Must be at least 1" },
{ "name": "embed", "message": "Not a field this request takes" }
]
}
}
```
* `code` says which error it is. It never changes, so branch on it in your code. * `message` explains it for you, not for your customer. Its wording can change. * `params` comes with a `validation_error` only, and names each field to fix. ## Error codes [Section titled “Error codes”](#error-codes) | Status | `code` | What to do | | ------ | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------- | | `400` | `validation_error` | Fix the fields named in `params`. | | `400` | `idempotency_key_required` | Send an `Idempotency-Key` header when you create a link. | | `400` | `amount_below_minimum` | Raise the amount. Your Stripe account has a minimum per payment, such as $0.50. | | `400` | `amount_above_maximum` | Lower the amount. | | `400` | `currency_not_supported` | Use a currency your Stripe account can charge in. | | `401` | `api_key_missing` | Send your key in the `Authorization` header. | | `401` | `invalid_api_key` | Check your key. If you regenerated it, use the new one. | | `403` | `provider_not_connected` | Connect your Stripe account in the app under [**Settings → Connectors**](https://app.cyan.cash/settings?tab=connectors). | | `403` | `provider_disconnected` | The link’s Stripe account no longer lets Cyan in. Reconnect it in the app. | | `404` | `payment_link_not_found` | Check the ID. A link is only found with the key of the business that created it. | | `404` | `route_not_found` | Check the path. | | `405` | `method_not_allowed` | Use a method the `Allow` header lists. | | `409` | `idempotency_key_in_use` | A request with the same key is still running. Send yours again in a moment. | | `409` | `payment_link_not_cancelable` | The link is `processing` or `paid`. Refund it in your Stripe Dashboard instead. | | `415` | `unsupported_media_type` | Send the body as JSON, with `Content-Type: application/json`. | | `422` | `idempotency_key_mismatch` | You sent this key before with a different body. Use a new key for a new payment. | | `500` | `internal_error` | Try again. | | `502` | `provider_unavailable` | Stripe couldn’t handle the request just now. Try again. | ## Handling errors in code [Section titled “Handling errors in code”](#handling-errors-in-code)
```js
const response = await fetch("https://api.cyan.cash/v1/payment-links", options);
const body = await response.json();
if (!response.ok) {
console.error(`Cyan ${response.status} ${body.error.code}: ${body.error.message}`);
throw new Error("We couldn't start the payment. Please try again.");
}
```
## Retries [Section titled “Retries”](#retries) Creating a link takes an `Idempotency-Key`, so retrying a create is always safe: * **The same key and body** returns the link the first request made, with `201`. Nothing is created twice, however many times you retry. * **The same key with a different body** returns `422 idempotency_key_mismatch`. * **Two requests with the same key at once:** the second may get `409 idempotency_key_in_use`. Retry it. Use a key that belongs to the payment, such as your order’s ID. Keys belong to your business, so they never clash with another business’s. What else to retry: * **`409 idempotency_key_in_use`, `500` and `502`:** yes. Wait a moment and send the same request again. * **A timeout:** yes, with the same `Idempotency-Key` when it was a create. * **Any other `4xx`:** no. The same request will fail the same way, so fix the cause first.
# The payment link object
> The fields of a payment link, its URL and its statuses.
A payment link is one request for one payment. You [create](/reference/create-payment-link/) it, your customer pays it, and you [retrieve](/reference/retrieve-payment-link/) it to see its status. Until it’s paid, you can [cancel](/reference/cancel-payment-link/) it. Every endpoint returns the same object:
```json
{
"id": "pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"amount": 4900,
"currency": "USD",
"description": "Logo design",
"customer_name": "Ada Lovelace",
"status": "pending",
"url": "https://pay.cyan.cash/pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"created_at": "2026-12-05T17:40:12.000Z"
}
```
## Fields [Section titled “Fields”](#fields) Every field is always present. One with no value is `null`. | Field | Type | Description | | --------------- | -------------- | --------------------------------------------------------------- | | `id` | string | The link’s ID. It starts with `pl_`. | | `amount` | integer | The amount in the currency’s smallest unit. `4950` is $49.50. | | `currency` | string | A three-letter ISO 4217 currency code, in uppercase. | | `description` | string | What the payment is for. Your customer sees it on the checkout. | | `customer_name` | string or null | Your customer’s name, or `null` when you didn’t set one. | | `status` | string | Where the payment stands. See below. | | `url` | string | The payment page. See below. | | `created_at` | string | When the link was created, as an ISO 8601 timestamp in UTC. | ## The URL [Section titled “The URL”](#the-url) `url` works two ways: * **As a link.** Send it to your customer, and they pay on a page hosted by Cyan. See [Send a payment link](/guides/payment-links/). * **In your chat.** Pass it to [`Cyan.mount`](/widget/mount/), and the same checkout appears as a message. See [Accept a payment in your chat](/guides/in-chat-checkout/). When your business has [Apple Pay](/guides/apple-pay/) turned on, `url` ends in `?wallets=apple_pay`. That tells the chat checkout to keep room for the button while it loads. Use the URL as you got it, query string included. ## Statuses [Section titled “Statuses”](#statuses) The status is always current: until a link is paid or canceled, Cyan checks the payment each time you retrieve it. | Status | Meaning | | ------------ | ----------------------------------------------------------------------------------------------------- | | `pending` | Waiting for payment. If a card is declined the link stays `pending`, and your customer can try again. | | `processing` | The payment was accepted and the bank is confirming it. | | `paid` | The payment succeeded. | | `canceled` | The link was canceled. It can no longer be paid. | A link stays open until it is paid or canceled. A refunded payment keeps the status `paid`. To see refunds, use the app’s [**Transactions**](https://app.cyan.cash/transactions) page or your Stripe Dashboard. ## Amounts and currencies [Section titled “Amounts and currencies”](#amounts-and-currencies) Amounts are integers in the currency’s smallest unit: cents for dollars and euros, whole yen for yen. | To charge | Send | | --------- | ------------------------------------ | | $49.50 | `"amount": 4950, "currency": "USD"` | | €120 | `"amount": 12000, "currency": "EUR"` | | ¥5,000 | `"amount": 5000, "currency": "JPY"` | `currency` defaults to `USD`. You can charge in any currency your Stripe account supports. The largest amount is `99999999`.
# Retrieve a payment link
> Returns a payment link with its current status. Use it to check whether a link has been paid.
GET `/v1/payment-links/{id}` The status is always current: until a link is paid or canceled, Cyan checks the payment each time you call. ## Headers [Section titled “Headers”](#headers) `Authorization` string header required Your API key as a bearer token: `Bearer cyan_test_...`. See [Authentication](/reference/authentication/). ## Path [Section titled “Path”](#path) `id` string path required The payment link’s ID, from the `id` you got when you created it. It starts with `pl_`. ## Response [Section titled “Response”](#response) Returns `200` with the [payment link](/reference/payment-link/). Any other status comes with an error: see [Errors](/reference/errors/). `id` string The link’s ID. `amount` integer The amount in the currency’s smallest unit. `currency` string A three-letter ISO 4217 currency code, in uppercase. `description` string What the payment is for. `customer_name` string or null Your customer’s name, or `null` when you didn’t set one. `status` string Where the payment stands: `pending`, `processing`, `paid` or `canceled`. See [statuses](/reference/payment-link/#statuses). `url` string The payment page, for your customer or for [`Cyan.mount`](/widget/mount/). `created_at` string When the link was created, as an ISO 8601 timestamp in UTC. Retrieve a payment link
```js
const response = await fetch(
"https://api.cyan.cash/v1/payment-links/pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
{
headers: {
Authorization: "Bearer cyan_test_...",
},
},
);
const link = await response.json();
```
* 200
```json
{
"id": "pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"amount": 4900,
"currency": "USD",
"description": "Logo design",
"customer_name": null,
"status": "paid",
"url": "https://pay.cyan.cash/pl_019d0a1b2c3d4e5f60718293a4b5c6d7",
"created_at": "2026-12-05T17:40:12.000Z"
}
```
* 401
```json
{
"error": {
"code": "invalid_api_key",
"message": "This API key isn't valid."
}
}
```
* 404
```json
{
"error": {
"code": "payment_link_not_found",
"message": "No payment link with this ID belongs to this business."
}
}
```
* 502
```json
{
"error": {
"code": "provider_unavailable",
"message": "The payment provider couldn't handle the request. Try again."
}
}
```
# Customize the checkout
> Match the in-chat checkout to your product with your name, your logo, a theme and an accent color.
The in-chat checkout should look like part of your product. You control four things: your name and logo, the theme, the accent color and the corners. ## Your name and logo [Section titled “Your name and logo”](#your-name-and-logo) The top of the checkout shows who your customer is paying. Set your business name and upload a logo in the Cyan app under [**Settings → Business**](https://app.cyan.cash/settings). Every checkout picks them up, with no code to change. ## Theme, accent and corners [Section titled “Theme, accent and corners”](#theme-accent-and-corners) Pass `appearance` when you mount the checkout:
```js
const checkout = Cyan.mount("#payment", {
url: link.url,
appearance: {
theme: "dark",
accent: "#7c3aed",
corners: "square",
},
});
```
| Option | Values | Default | What it changes | | --------- | -------------------------------- | ------------------------------ | ----------------------------------------------------------- | | `theme` | `"auto"`, `"light"`, `"dark"` | `"auto"` | Light or dark. `"auto"` follows your customer’s device. | | `accent` | A hex color, such as `"#7c3aed"` | A neutral that suits the theme | The **Pay** button and the highlight on the field in focus. | | `corners` | `"rounded"`, `"square"` | `"rounded"` | The corners of the card, fields and buttons. | Pick any accent you like. Cyan chooses dark or white text for the **Pay** button so it stays readable. Write the accent as a six-digit hex color. Any value Cyan doesn’t recognize falls back to the default. ## Try it before you ship it [Section titled “Try it before you ship it”](#try-it-before-you-ship-it) The [**Widget**](https://app.cyan.cash/widget) page in the Cyan app is a live preview. Switch the theme, try accent colors and change the corners, and see the checkout with your own name and logo. When it looks right, copy the snippet the page writes for you. ## Follow your app’s light and dark mode [Section titled “Follow your app’s light and dark mode”](#follow-your-apps-light-and-dark-mode) If your product has its own theme switch, change the checkout to match with `update`. The payment form stays loaded, so nothing your customer typed is lost.
```js
checkout.update({
appearance: { theme: "light", accent: "#7c3aed", corners: "square" },
});
```
`update` sets the whole appearance at once, so pass every option you want to keep. See the [`Cyan.mount` reference](/widget/mount/) for everything else the widget does.
# Cyan.mount
> Reference for widget.js, the script that puts the Cyan checkout in your chat.
`widget.js` adds one global, `Cyan`, with one function: `mount`. For a walkthrough, start with [Accept a payment in your chat](/guides/in-chat-checkout/). ## Load the script [Section titled “Load the script”](#load-the-script)
```html
```
## `Cyan.mount(target, options)` [Section titled “Cyan.mount(target, options)”](#cyanmounttarget-options) Puts a checkout in an element and returns a handle to it.
```js
const checkout = Cyan.mount("#payment", {
url: link.url,
appearance: { theme: "auto", accent: "#0e7490", corners: "rounded" },
onReady() {},
onPaid({ link }) {},
onProcessing({ link }) {},
onError({ message }) {},
});
```
### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------------------- | ----------------- | -------------------------------------------------------------------------------------------- | | `target` | string or Element | Where the checkout goes: an element, or a CSS selector for one. | | `options.url` | string | Required. A payment link’s `url`, as the API returned it. | | `options.appearance` | object | Optional. How the checkout looks. See below. | | `options.onReady` | function | Optional. Called when the payment form is ready. | | `options.onPaid` | function | Optional. Called with `{ link }` when the payment succeeds. | | `options.onProcessing` | function | Optional. Called with `{ link }` when the payment is accepted and the bank is confirming it. | | `options.onError` | function | Optional. Called with `{ message }` when a payment attempt fails. | In `onPaid` and `onProcessing`, `link` is the payment link’s ID, such as `"pl_019d0a1b2c3d4e5f60718293a4b5c6d7"`. ### Appearance [Section titled “Appearance”](#appearance) | Option | Values | Default | | --------- | ------------------------------------------ | ---------------------------------------------- | | `theme` | `"auto"`, `"light"`, `"dark"` | `"auto"`, which follows your customer’s device | | `accent` | A six-digit hex color, such as `"#0e7490"` | A neutral that suits the theme | | `corners` | `"rounded"`, `"square"` | `"rounded"` | See [Customize the checkout](/widget/customize-checkout/) for what each option changes. ### Returns [Section titled “Returns”](#returns) A handle with two methods: | Method | Description | | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | | `update({ appearance })` | Restyles the checkout without reloading the payment form. It sets the whole appearance, so pass every option you want to keep. | | `unmount()` | Removes the checkout from the page. | ### Errors [Section titled “Errors”](#errors) `Cyan.mount` throws if it can’t start: | Message | Cause | | -------------------------------------------------------------------- | -------------------------------------------------- | | `Cyan.mount: target element not found` | `target` didn’t match an element. | | `Cyan.mount: url must be a payment link's url from this Cyan server` | `url` is missing, or isn’t a payment link’s `url`. | ## Callbacks [Section titled “Callbacks”](#callbacks) | Callback | Runs | | -------------- | ----------------------------------------------------------------------------------------------- | | `onReady` | Once, when the payment form is ready to use. | | `onPaid` | When a payment succeeds. Also when you mount a link that is already paid. | | `onProcessing` | When a payment is accepted and still being confirmed. Also when you mount a link in that state. | | `onError` | Each time an attempt fails. Your customer can try again in the same form. | Because `onPaid` can run more than once for the same link, make your handler safe to repeat. The callbacks run in your customer’s browser. Use them to update your chat, and [confirm the payment](/guides/confirm-payments/) on your server. ## What your customer sees [Section titled “What your customer sees”](#what-your-customer-sees) The checkout always shows the right state for the payment link: | Link status | The checkout shows | | ------------ | -------------------------------------------------------------------- | | `pending` | Your name and logo, the amount, what it’s for, and the payment form. | | `processing` | “Payment processing”, while the bank confirms. | | `paid` | “Payment complete”. | | `canceled` | “Link expired”. | While it loads, the checkout shows a placeholder in its own shape, then sizes itself to its content. Give the element you mount it in a width, and leave the height alone. ## Security [Section titled “Security”](#security) The checkout runs in a frame on Cyan’s domain. Card details are entered there and never reach your page, your scripts or your servers.