Getting started with the Thpaste API

Create, list, edit and delete pastes and pull your analytics from scripts, bots and CI — a hands-on guide to the free Thpaste API with curl, Python and JavaScript examples, rate limits, errors and idempotent retries.

Thpaste team · 5 min read
The Thpaste API in 10 minutes
On this page
  1. Step 1 — get a key
  2. Step 2 — check it works
  3. Step 3 — create your first paste
  4. The same thing in Python and JavaScript
  5. Every endpoint at a glance
  6. Limits and how to stay inside them
  7. Errors you can handle in one place
  8. Safe retries with Idempotency-Key
  9. Ideas to build

Everything you can do on the website, your code can do too. The Thpaste API is a small, predictable JSON API: make pastes from a CI job, post a daily report from a bot, back up your pastes, or build your own dashboard from your view stats. It's free with every account. This guide takes you from zero to your first paste in about ten minutes.

7endpoints — create, list, read, edit, delete, stats, me
60requests a minute per key
500new pastes a day per account
10API keys per account

Step 1 — get a key

  1. 1
    Create a free account

    Or sign in at thpaste.com/login.

  2. 2
    Open API keys

    Dashboard sidebar → Account → API keys → Create key.

  3. 3
    Copy it straight away

    The key starts with tp_ and is shown once. Store it in your password manager or your server's secrets.

The API keys page
Create, name and revoke keys — up to 10 at a time

Keep keys on servers

A key acts as your account. Never put one in a web page, a mobile app or a public repository. If a key leaks, revoke it from the same page — it stops working instantly.

Step 2 — check it works

Send the key as a Bearer token on every request:

curl https://thpaste.com/api/v1/me \
  -H "Authorization: Bearer tp_YOUR_KEY"

You'll get your account back — id, email, username, profile link and paste count — wrapped in data.

Step 3 — create your first paste

curl -X POST https://thpaste.com/api/v1/pastes \
  -H "Authorization: Bearer tp_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title": "Setup notes", "content": "Step 1: ...", "language": "markdown"}'

The answer is 201 with the new paste — its id, link, settings and size. It appears in your dashboard like any paste made on the website, and your automatic signature is added if you've set one.

FieldRequiredWhat it is
content✓The text, up to 512 KB
title✗Up to 120 characters
language✗plain (default), markdown, richtext or a code language such as python or json
visibility✗unlisted (default) or public
expiry✗never (default), 10m, 1h, 1d, 1w, 1m or burn
password✗Readers must enter it to open the paste
slug✗A custom link: thpaste.com/s/your-slug (3–48 lowercase letters, numbers and hyphens)

The same thing in Python and JavaScript

import os, requests

API = "https://thpaste.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['THPASTE_KEY']}"}

r = requests.post(f"{API}/pastes", headers=HEADERS, json={
    "title": "Nightly report",
    "content": open("report.md").read(),
    "language": "markdown",
    "expiry": "1w",
})
r.raise_for_status()
print("Shared:", r.json()["data"]["url"])
const res = await fetch("https://thpaste.com/api/v1/pastes", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.THPASTE_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ title: "Build log", content: log, language: "bash" }),
});
const { data } = await res.json();
console.log("Shared:", data.url);

Every endpoint at a glance

MethodPathDoes
POST/pastesCreate a paste
GET/pastesList your pastes, newest first — page, per_page (1–100) and q to search
GET/pastes/{id}One of your pastes, with its content
PATCH/pastes/{id}Change the title, content and/or custom link
DELETE/pastes/{id}Delete it for good
GET/statsYour analytics — range of 24h, 7d, 30d, 90d or all, optionally for one paste
GET/meThe account the key belongs to

The full reference, with every field of every response, lives at **/docs/api**.

The API reference
The API reference at thpaste.com/docs/api

Limits and how to stay inside them

API limits per minute
All requests (per key)60
New pastes (per account)30

Every response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. Go over and you get 429 with a Retry-After header in seconds — wait that long and carry on. New pastes are also capped at 500 a day per account.

Errors you can handle in one place

Every error, including the 429, has the same shape:

{
  "error": {
    "code": "VALIDATION_FAILED",
    "message": "Some fields aren't valid.",
    "details": { "expiry": "One of: never, 10m, 1h, 1d, 1w, 1m, burn." }
  }
}
StatusCodeMeaning
400BAD_REQUESTThe body isn't a JSON object
401UNAUTHORIZEDMissing, unknown or revoked key
404NOT_FOUNDNo such paste on your account
409CONFLICTThat custom link is taken
422VALIDATION_FAILEDA field is wrong — see details
429RATE_LIMITEDSlow down — see Retry-After

Safe retries with Idempotency-Key

Networks fail. If a create request times out, you don't know whether the paste was made. Send an Idempotency-Key header (any unique string up to 100 characters): repeating the same key with the same body within 10 minutes returns the original paste — marked Idempotency-Replayed: true — instead of making a duplicate.

Ideas to build

Chat bots

A Telegram or Discord command that turns a long message into a paste link.

CI logs

Upload failing test output and post the link in your pull request.

Weekly stats

Pull /stats every Monday and send yourself a summary.

Backups

List and download all your pastes to your own storage.

Get your API key

Free with every account — up to 10 keys, revoke any time.

Open API keys

Share something now

Rich text, Markdown or code — get a short link in seconds. No account needed.

Create a paste

Keep reading

Guide · 5 min read

Everything Thpaste can do: the complete feature tour

A guided, screenshot-by-screenshot tour of every Thpaste feature — rich text, Markdown and code pastes, private sharing, translation, link previews, analytics, profiles, Creator Mode and the API.