Complete developer documentation for integrating TruthLayer's bias-correction middleware into your AI applications. TruthLayer works as a drop-in replacement for any OpenAI-compatible API endpoint.
API Overview
TruthLayer provides a REST API that intercepts LLM requests, applies multi-layered bias correction, and returns balanced, perspective-corrected responses. The API is compatible with OpenAI's chat completions format, making integration as simple as changing your base URL and adding an API key.
Authentication
All API requests require a TruthLayer API key passed in the Authorization header as a Bearer token. API keys are prefixed with "tl_" and can be generated from your TruthLayer dashboard. Keep your API key secure and never expose it in client-side code.
Endpoints
POST /api/truthlayer/v1/completions — Primary endpoint for bias-corrected completions. Accepts the same parameters as OpenAI's chat completions API with additional TruthLayer-specific fields: profile (correction profile to apply), provider_api_key (for non-OpenAI models), and correction_level (standard, aggressive, or minimal).
GET /api/truthlayer/v1/profiles — Returns available correction profiles and their descriptions.
GET /api/truthlayer/v1/usage — Returns current token usage and remaining quota for the billing period.
GET /api/truthlayer/v1/health — Health check endpoint for monitoring.
Correction Profiles
Seven domain-specific profiles are available: standard (general-purpose bias correction), journalism (balanced reporting), legal (prosecution/defense balance), medical (patient autonomy focus), education (intellectual pluralism), policy (political spectrum balance), and corporate (stakeholder-neutral communications). Specify the profile in your request to apply domain-appropriate corrections.
Supported Models
TruthLayer supports OpenAI (gpt-4o, gpt-5, gpt-5.2), Google (gemini-2.5-flash, gemini-2.5-pro), Anthropic (claude-sonnet-4, claude-opus), xAI (grok-2), and DeepSeek (deepseek-chat). For non-OpenAI models, include your provider API key in the provider_api_key field.
Code Example
Integration requires minimal code changes. Replace your OpenAI base URL with the TruthLayer endpoint, add your TruthLayer API key, and specify a correction profile. The response format matches OpenAI's standard chat completion response with additional metadata about corrections applied.
Rate Limits
Rate limits vary by plan: Free (10 requests/minute), Creator (60 requests/minute), Professional (200 requests/minute), Business (1000 requests/minute). Rate limit headers are included in every response.