FOR DEVELOPERS

TryCode API

Create posts, manage access, and discover public code from your app.

REST · JSON Bearer key Read: 120/min
01 / GETTING STARTED

Quickstart

Base path: /api/v1. For local development, use http://localhost:3000, and replace the domain with your service URL in production. All v1 requests require the header Authorization: Bearer <key>.

cURL
curl "http://localhost:3000/api/v1/codes?limit=20" \
  -H "Authorization: Bearer $TRYCODE_API_KEY"

Keep the key on your server or in an environment variable. Do not put it in browser JavaScript or a public repository.

02 / ACCESS RULES

Limits and views

Per-key limits per minute: 120 reads, 10 creates, and 60 updates or deletes. Counters are independent. Responses include X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. On a 429 response, wait the seconds specified in Retry-After.

Reading another public post through GET /api/v1/public/codes/{id} increments the view count and uses the configured limit. Reading your own post does not count. Password-protected posts can be opened in the web editor; API v1 returns 423 for them.

Open OpenAPI specification
03 / ACCESS

API keys

Create a key for your current account. Without signing in, it is linked to this guest browser; after GitHub sign-in, your posts and keys move to the account. A key can change only your posts and read the public catalog. Guest key management depends on this browser's cookie.

Your API keys

A key gives access to your posts through the REST API

Loading keys…

04 / ENDPOINTS

API endpoints

All endpoints return JSON. Your posts and public posts are paginated in groups of 20; pass nextCursor in the cursor parameter to get the next page.

MethodRoutePurpose
GET/api/v1/codesList your posts
POST/api/v1/codesCreate post
GET/api/v1/codes/{id}Get your post
PATCH/api/v1/codes/{id}Update content and settings
DELETE/api/v1/codes/{id}Delete your post
GET/api/v1/public/codesFind public posts
GET/api/v1/public/codes/{id}Read a public post
05 / EXAMPLES

Request examples

Create post

Add a title, language, and content, and optionally publish the post.

cURL
curl -X POST "http://localhost:3000/api/v1/codes" \
  -H "Authorization: Bearer $TRYCODE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title":"sum.ts","language":"typescript","content":"const sum = (a: number, b: number) => a + b;","isPublic":true}'

Update post

Send only the fields you want to change. Content updates in open editors too.

cURL
curl -X PATCH "http://localhost:3000/api/v1/codes/ABC123" \
  -H "Authorization: Bearer $TRYCODE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"content":"const sum = (a: number, b: number) => { return a + b; };","maxViews":100}'

Find public posts

Filter the catalog by title and language. The preview field is null.

cURL
curl "http://localhost:3000/api/v1/public/codes?q=sum&language=typescript" \
  -H "Authorization: Bearer $TRYCODE_API_KEY"
06 / FORMAT

Responses and errors

A create or read response contains a record. Lists return data and nextCursor. Timestamps and expiresAt use Unix time in milliseconds.

JSON
{
  "record": {
    "id": "ABC123",
    "title": "sum.ts",
    "language": "typescript",
    "content": "const sum = (a: number, b: number) => a + b;",
    "isPublic": true,
    "allowOthersToEdit": false,
    "canEdit": true,
    "isOwner": true,
    "passwordProtected": false,
    "expiresAt": null,
    "maxViews": null,
    "burnAfterRead": false,
    "viewCount": 0,
    "createdAt": 1795046400000,
    "updatedAt": 1795046400000
  }
}

Errors use the format {"error":{"code":"not_found","message":"Post not found"}}. Common statuses:

400 Invalid fields or parameters401 Key missing or revoked404 Post not found or unavailable409 Edit conflict423 Password required429 Rate limit exceeded