Documentation
API Reference
Create and retrieve snippets programmatically.
Base URL
https://pastecn.com/api/v1Authentication
Password-protected snippets require Bearer token authentication. Include the password in the Authorization header.
Authorization: Bearer <password>Public snippets do not require authentication.
/snippets
Create a new snippet. The ID is generated server-side.
Request Body
{
"name": "my-component",
"type": "component",
"files": [
{
"path": "components/my-component.tsx",
"content": "export function MyComponent() {\n return <div>Hello</div>\n}"
}
],
"password": "optional-password"
}Response
201 Created{
"id": "xK9mN2pL",
"url": "https://pastecn.com/p/xK9mN2pL",
"registryUrl": "https://pastecn.com/r/xK9mN2pL",
"password": "generated-password"
}Example
/snippets/{id}
Retrieve a snippet by ID. Protected snippets require Bearer authentication.
Response
200 OK{
"id": "xK9mN2pL",
"name": "my-component",
"type": "component",
"files": [
{
"path": "components/my-component.tsx",
"content": "export function MyComponent() {...}",
"language": "tsx"
}
],
"meta": {
"primaryLanguage": "tsx",
"fileCount": 1
},
"isProtected": false
}Example (Public Snippet)
Example (Protected Snippet)
Snippet Types
The type field determines how the snippet is registered in the shadcn registry.
fileMiscellaneous files. Config files, types, or any other file.
componentReact components. Single-file UI elements.
hookReact hooks. Custom state management or side effects.
libUtility functions and helpers. Pure logic, no UI.
blockComplex components with multiple files. Combines components, hooks, utils, and types into a complete feature.
Error Codes
All errors return a JSON response with a code and message field.
{
"code": "NOT_FOUND",
"message": "Snippet not found"
}| Code | HTTP | Description |
|---|---|---|
VALIDATION_ERROR | 400 | Invalid request body or parameters |
INVALID_ID | 400 | Snippet ID format is invalid |
AUTH_REQUIRED | 401 | Protected snippet requires Bearer token |
INVALID_PASSWORD | 401 | Bearer token does not match password |
NOT_FOUND | 404 | Snippet does not exist |
ID_COLLISION | 409 | Generated ID already exists (retry) |
RATE_LIMITED | 429 | Too many requests |
INTERNAL_ERROR | 500 | Server error |