Overview
The Prompts.dev API uses JWT (JSON Web Token) based authentication to secure endpoints. After logging in via OAuth, you’ll receive a JWT token that must be included in subsequent API requests.Token Format
JWT tokens are issued using the HS256 signing algorithm and contain the following claims:The unique identifier of the authenticated user
Subject claim (same as user_id)
Issued at timestamp (Unix time)
Expiration timestamp (Unix time)
Tokens expire after a configured period (typically 24-72 hours). The exact expiration time is set by the
JWT_EXPIRY_HOURS environment variable on the server.Token Verification
Tokens are verified using the server’s JWT secret. The authentication middleware:- Extracts the token from the
Authorizationheader - Validates the token signature using HS256
- Checks the expiration time
- Extracts the
user_idclaim and adds it to the request context
internal/auth/token.go:29 and internal/auth/middleware.go:23
Making Authenticated Requests
To authenticate API requests, include your JWT token in theAuthorization header using the Bearer scheme:
Authentication Errors
If authentication fails, the API returns a401 Unauthorized response:
Missing Token
Invalid or Expired Token
The middleware automatically aborts the request and returns an error response when authentication fails. No further processing occurs.
Protected Endpoints
The following endpoints require authentication:POST /v1/prompts- Create a new promptPOST /v1/prompts/:id/versions- Upload a new version
cmd/api/main.go:60
Extracting User Information
In authenticated requests, the user ID is available in two ways: From Gin Context:internal/auth/middleware.go:47