REST API v1

One-time secret API

Create encrypted, single-use links from your own tools. Encrypt the text locally, build the recipient link from the API response, and check delivery with the private status token.

Quick start

Use Node.js 20 or later. Put the Web Crypto module and a file named create-link.mjs in the same folder. Save the example below to that file, then set ONETIME_API_KEY in your environment.

create-link.mjs
import { prepareSecret, revealEnvelope, statusEnvelope } from './crypto.mjs';

const origin = new URL('https://onetime.ie/');
const apiKey = process.env.ONETIME_API_KEY;
if (!apiKey) throw new Error('Set ONETIME_API_KEY first.');

const secret = await prepareSecret('fictional demo password', 3600);
const response = await fetch(new URL('/api/v1/secrets', origin), {
    method: 'POST',
    redirect: 'error',
    headers: {
        Authorization: 'Bearer ' + apiKey,
        'Content-Type': 'application/json',
    },
    body: JSON.stringify(secret.request),
});
if (response.status !== 201) {
    throw new Error('Creation failed (HTTP ' + response.status + ').');
}

const { id, visit_token, status_token, expires_at } = await response.json();
const recipient = await revealEnvelope(id, visit_token, secret);
const status = statusEnvelope(id, status_token);
console.log('Recipient link:', new URL('/reveal#' + recipient, origin).href);
console.log('Private status link:', new URL('/status#' + status, origin).href);
console.log('Expires:', expires_at);

Run node create-link.mjs in a private terminal. Send the recipient link and keep the status link for yourself. Both URLs contain access tokens. Keep the output out of shared logs.

For a protected recipient link, call revealEnvelope(id, visit_token, secret, passphrase) and share the passphrase separately. The passphrase stays in your client.

Instructions for AI coding agents

Copy these instructions into your coding assistant alongside a short description of what you want to build. They include the API contract, a working create-link example and what to test.

Open the Markdown guide
# Integrate the onetime.ie API v1

Implement an integration that creates encrypted, one-time links for UTF-8 text and can optionally read the sender's link status. Work within the host project's conventions. Add mock-based tests and explain how to run with an operator-issued API key.

API origin: https://onetime.ie/
API reference: https://onetime.ie/api-docs
Link format: https://onetime.ie/developers/link-format
Web Crypto module: https://onetime.ie/assets/crypto.mjs

## Credentials and data flow

- Use a trusted integration runtime, such as Node.js 20+. Read `ONETIME_API_KEY` from the environment or a secrets manager. Do not expose it in a browser bundle or a repository.
- Send `Authorization: Bearer <key>` and `Content-Type: application/json` over HTTPS. Disable redirects when sending credentials. A create key needs `secrets:create`. A status key needs `status:read` for the same integration.
- Use the Web Crypto module as a local dependency. Review and bundle it with your application. Keep the plaintext, passphrase, encryption key and raw release token on the trusted client during creation.
- Keep credentials, complete URLs, fragments and status tokens out of logs, analytics and error reports. Return links only to their intended holders. Send an optional passphrase over a separate channel.

## Create a link

1. Call `prepareSecret(text, ttlSeconds)`. Text must be 1–16,384 UTF-8 bytes. The allowed TTL values are `900`, `3600`, `86400` and `604800` seconds.
2. Send exactly `secret.request` as JSON to `POST /api/v1/secrets`. Its fields are `version` (integer 1), `token_hash` (lowercase hex SHA-256 of the raw 32-byte release token), `nonce`, `ciphertext` and `ttl_seconds`. The nonce and ciphertext are unpadded base64url. The body limit is 24 KiB.
3. Check for HTTP `201`. The response contains `id`, `expires_at`, `visit_token` and `status_token`. Build the links locally using the module, keeping the fragments after the `#`. Share the recipient URL. Keep the status URL private.

```js
import { prepareSecret, revealEnvelope, statusEnvelope } from './crypto.mjs';

const origin = new URL('https://onetime.ie/');
const apiKey = process.env.ONETIME_API_KEY;
if (!apiKey) throw new Error('Set ONETIME_API_KEY');

export async function createLink(text, ttlSeconds = 3600, passphrase = '') {
    const secret = await prepareSecret(text, ttlSeconds);
    const response = await fetch(new URL('/api/v1/secrets', origin), {
        method: 'POST',
        redirect: 'error',
        headers: {
            Authorization: 'Bearer ' + apiKey,
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(secret.request),
    });
    if (response.status !== 201) {
        throw new Error('Link creation failed (HTTP ' + response.status + ')');
    }

    const { id, expires_at, visit_token, status_token } = await response.json();
    const recipient = await revealEnvelope(id, visit_token, secret, passphrase);
    return {
        recipientUrl: new URL('/reveal#' + recipient, origin).href,
        statusUrl: new URL('/status#' + statusEnvelope(id, status_token), origin).href,
        expiresAt: expires_at,
    };
}
```

## Read status and handle errors

Send `{ "id": "...", "token": "..." }` to `POST /api/v1/secrets/status` with the status scope. The value of `token` is the returned `status_token`. If starting with a private URL, call `parseStatus(url.hash.slice(1))` for the request body. The body limit is 1 KiB.

HTTP `200` returns `state`, `created_at`, `expires_at`, `opened_at` and `revealed_at`. The states are `Waiting`, `Opened`, `Revealed` and `Expired`. An opening can come from an automated visitor. A reveal means the server released ciphertext. Neither timestamp verifies who read the text. Status expires 24 hours after link expiry.

Errors have an `error` field. Treat `401` as missing, invalid or revoked credentials, `403` as denied scope or origin, `404` as unavailable status, and `413` or `422` as invalid payload. On `429`, respect `Retry-After`. A timed-out create may have succeeded. A new create request makes a separate link.

Opening or previewing the recipient page does not use the link. Leave reveal to the recipient in the browser. Release consumes the record once, so avoid automatic reveal, polling for plaintext and retries after an uncertain reveal.

## Verify the integration

Mock the API for routine tests. Assert that the create request contains ciphertext and the token hash but never plaintext, the passphrase, the key or the raw release token. Check both generated URLs, status token handling, non-success responses and redaction. Use fictional data for a live smoke test only when a user supplies an authorised key and asks to run it.

Authentication

Ask the service operator for a key scoped to your integration. Send it as Authorization: Bearer <key> over HTTPS with Content-Type: application/json.

  • secrets:create creates a new link.
  • status:read checks links created by the same integration. This also works with a replacement key for that integration.

Errors and limits

Secret text can be up to 16 KiB in UTF-8. Request bodies are limited to 24 KiB for creation and 1 KiB for status. The default limit is 120 requests per integration key per 15 minutes. The shared creation limit is 300 links per minute.

Error bodies contain one field, for example {"error":"rate_limited"}.

HTTP statusErrorWhat to check
401unauthorizedCheck the Bearer key and whether it was revoked.
403forbiddenCheck the key's scope and request origin.
404not_foundCheck the record ID, status token and integration. Status is kept for up to 24 hours after expiry.
405method_not_allowedUse POST for the documented API paths.
413payload_too_largeReduce the request size.
422invalid_requestCheck the JSON fields, lengths and encoding.
429rate_limitedWait for the interval in Retry-After.
503unavailableTry again later. A fresh create request makes a new link.

Frequently asked questions

Can a public frontend call the integration API directly?

Keep the Bearer key on a trusted server or integration runtime. For account-free sharing, open the website so the user can create and share a link there.

What should I do if my create request times out?

The first request may have succeeded. A new request makes a separate link. Share only a URL whose creation response you received.

Does checking status consume the recipient link?

No. Status uses a separate token and reads the link state without revealing the encrypted message.