Skip to main content

Error Handling

The Tokencraft API uses conventional HTTP status codes to indicate success or failure of requests. All error responses include a JSON body with an error field describing the problem.

Error Response Format

Status Codes

2xx Success

4xx Client Errors

5xx Server Errors

Common Errors

401 Unauthorized

Cause: Missing or invalid API token
Solutions:
  • Verify your token is correct
  • Check the Authorization header format: Bearer tkc_xxx
  • Ensure the token hasn’t been revoked
  • Generate a new token if necessary
Example:

404 Not Found

Cause: Resource doesn’t exist or you don’t have access
Solutions:
  • Verify the resource ID is correct
  • Ensure you have access to the resource
  • Check for typos in the endpoint URL

403 Forbidden

Cause: Scope missing or workspace role/plan does not allow the operation
Solutions:
  • Ensure your token includes the required scope (write:tokens or export:tokens)
  • Verify your workspace role (TEAM viewers cannot write)
  • Verify the workspace owner plan allows API write access

410 Gone (Deprecated Session Endpoint)

Cause: Legacy workspace invitation link endpoints are deprecated
Affected endpoints:
  • POST /api/workspaces/invitations/accept
  • GET /api/workspaces/invitations/verify
  • DELETE /api/workspaces/invitations/{id}

400 Bad Request

Cause: Invalid input data
Solutions:
  • Check required fields are provided
  • Validate input format matches API expectations
  • Review the endpoint documentation
Example:

429 Rate Limit Exceeded

Cause: Too many requests in a short time
Solutions:
  • Wait 60 seconds before retrying
  • Implement exponential backoff
  • Reduce request frequency
  • Cache API responses
See Rate Limits for details.

500 Internal Server Error

Cause: Server-side error
Solutions:
  • Retry the request after a short delay
  • Check status page for outages
  • Contact support if the issue persists

Error Handling Examples

JavaScript/TypeScript

Python

With Retry Logic

Validation Errors

When creating or updating resources, validation errors provide specific field information:

Best Practices

1. Always Check Response Status

2. Implement Retry Logic

For rate limits and server errors:

3. Log Errors Appropriately

4. Provide User-Friendly Messages

Debugging Tips

1. Use Verbose Logging

2. Check Request Format

Ensure:
  • Authorization header is present and correct
  • Content-Type header is set for POST/PATCH
  • Request body is valid JSON
  • URL is properly formatted

3. Validate Token

Test your token with a simple request:

4. Check Rate Limit Headers

Response headers include rate limit info:

Getting Help

If you encounter persistent errors:
  1. Check the documentation
  2. Review your request format and authentication
  3. Check for service status updates
  4. Contact support with:
    • Request details (endpoint, method, headers)
    • Response status and error message
    • Timestamp of the request
    • Your API token ID (not the full token)

Next Steps

Rate Limits

Understand rate limiting

Authentication

Learn about API authentication