Skip to Content
⭐ CraftJS is open source. Star on GitHub →
DocsAPI Routes

API Routes

This section documents all API endpoints available in CraftJS.

Overview

CraftJS provides RESTful API endpoints for all major features:

EndpointMethodDescription
/api/auth/*VariousAuthentication (Better Auth)
/api/chatPOSTAI chat completions
/api/chatsGETList user chats
/api/chats/[id]GET/DELETEGet or delete a chat
/api/uploadPOSTGet file upload URL
/api/checkoutPOSTCreate payment checkout
/api/billing/portalPOSTAccess billing portal
/api/webhooks/*POSTWebhook handlers

Authentication

All API routes (except webhooks and public endpoints) require authentication. Include the session cookie or use the auth header.

Authentication is automatic when using cookies (default browser behavior).

API Key (Coming Soon)

For programmatic access:

curl -X POST https://yourapp.com/api/chat \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"messages": [...]}'

Rate Limiting

API endpoints are rate limited per user:

PlanLimit
Free10 requests/minute
Pro100 requests/minute
Enterprise1000 requests/minute

Rate limit headers are included in responses:

X-RateLimit-Remaining: 9 X-RateLimit-Reset: 1699999999999

Error Responses

All errors follow a consistent format:

{ "error": "Error message", "code": "ERROR_CODE", "details": {} }

Common Error Codes

StatusCodeDescription
400INVALID_REQUESTInvalid request body
401UNAUTHORIZEDNot authenticated
403FORBIDDENNot authorized for this resource
404NOT_FOUNDResource not found
429RATE_LIMITEDRate limit exceeded
500INTERNAL_ERRORServer error

CORS

CORS is configured to allow requests from:

  • Your production domain
  • localhost in development

To customize, update next.config.ts:

async headers() { return [ { source: "/api/:path*", headers: [ { key: "Access-Control-Allow-Origin", value: "https://yourdomain.com" }, { key: "Access-Control-Allow-Methods", value: "GET,POST,DELETE" }, { key: "Access-Control-Allow-Headers", value: "Content-Type, Authorization" }, ], }, ] }

API Sections

Last updated on