API Reference
gotcontext.ai compresses text and code before it enters an AI context window — saving up to 95% of input tokens. The REST API is simple: send text, get back a compressed skeleton plus token stats.
Quick Start#
Get your API key from the dashboard, then make your first compression call:
"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/compress \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{"text": "Your document text here...", "fidelity": "balanced"}'MCP Server#
gotcontext.ai hosts a remote MCP (Model Context Protocol) server at https://api.gotcontext.ai/mcp. Connect any MCP-compatible AI tool to get compression, ingestion, and context management tools without running anything locally.
Claude Code
{
"mcpServers": {
"gotcontext": {
"url": "https://api.gotcontext.ai/mcp",
"headers": {
"Authorization": "Bearer gc_your_key_here"
}
}
}
}Cursor
{
"mcpServers": {
"gotcontext": {
"url": "https://api.gotcontext.ai/mcp",
"headers": {
"Authorization": "Bearer gc_your_key_here"
}
}
}
}VS Code (settings.json)
{
"mcp": {
"servers": {
"gotcontext": {
"url": "https://api.gotcontext.ai/mcp",
"headers": {
"Authorization": "Bearer gc_your_key_here"
}
}
}
}
}Gemini CLI (settings.json)
{
"mcpServers": {
"gotcontext": {
"url": "https://api.gotcontext.ai/mcp",
"type": "http",
"headers": {
"Authorization": "Bearer gc_your_key_here"
},
"timeout": 30000
}
}
}Authentication
All MCP connections require a gc_-prefixed API key passed in the Authorization header. Create one from your dashboard.
For custom MCP clients
The MCP endpoint uses Streamable HTTP transport. Requests must include Accept: application/json, text/event-stream and carry the Mcp-Session-Id header from the initialize response on all subsequent calls. Claude Code, Cursor, and VS Code handle this automatically.
Recommended: Add project instructions
For best results, add a CLAUDE.md (or AGENTS.md) to your project root so the AI knows when and how to use gotcontext compression. Without this, the AI may not use the tools effectively. Copy this starter:
# gotcontext.ai Compression
This project uses gotcontext.ai for semantic compression via MCP.
## When to compress
- Before sending large files or docs to the AI context window
- When terminal output is verbose (git diff, test results, logs)
- When reviewing code across many files
## Compression workflow
1. Use `ingest_context` to add a document (give it a unique file_id)
2. Use `read_skeleton` to get the compressed version
3. Use `search_semantic` to find specific sections by query
4. Use `filter_cli_output` to compress git diffs, pytest output, etc.
## Tips
- Use `estimate_tokens` first to see if compression is worthwhile
- For code files, the compressor understands function/class boundaries
- Use `get_compression_presets` to see available fidelity levels
- Call `tool_help` for documentation on any specific toolAuthentication#
All API requests require a Bearer token in the Authorization header. Two token types are supported:
API Keys (recommended)
Prefixed with gc_. Create keys in the dashboard or viaPOST /v1/keys. Keys are permanent until revoked and can be rotated at any time.
Authorization: Bearer gc_a1b2c3d4e5f6...Clerk JWT (session tokens)
Short-lived tokens issued by Clerk after sign-in. Used automatically by the dashboard frontend. For programmatic access, API keys are preferred.
Authorization: Bearer eyJhbGciOi...Compression#
/v1/compressCompress any text document using graph-based semantic compression. Achieves 80–95% token reduction on medium-to-large documents. Optionally supply a query to guide the compressor toward sections most relevant to your question.
Request body
{
"text": string, // required — document to compress (min 1 char)
"fidelity": string, // optional — "abstract" | "outline" | "balanced" | "detailed" | "raw"
// default: "balanced"
"query": string|null, // optional — query-guided mode; prioritises relevant sections
"cost_model": string|null // optional — model name for cost estimate (e.g. "claude-opus-4")
}Response
{
"compressed": string, // compressed skeleton text
"stats": {
"original_tokens": number,
"compressed_tokens": number,
"savings_pct": number, // e.g. 87.4
"compression_ratio": number, // e.g. 7.9
"estimated_cost_saved": string|null // e.g. "$0.042" — only when cost_model supplied
}
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/compress \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{
"text": "Transformer models fundamentally changed NLP...",
"fidelity": "balanced",
"query": "attention mechanism",
"cost_model": "claude-sonnet-4-6"
}'Error responses
/v1/compress-codeAST-aware code compression. Parses function/class boundaries, extracts imports and docstrings, ranks symbols by PageRank on the dependency graph. Returns a skeleton preserving signatures and docstrings. Significantly better than plain text compression for code.
Request body
{
"code": string, // required — source code to compress (min 1 char)
"language": string|null, // optional — hint: "python"|"javascript"|"typescript"|"java"|"go"|"rust"|"cpp"
// auto-detected from content when omitted
"fidelity": string, // optional — same levels as /compress, default: "balanced"
}Response
{
"compressed": string,
"stats": {
"original_tokens": number,
"compressed_tokens": number,
"savings_pct": number,
"language_detected": string // e.g. "python", "javascript", "unknown"
}
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/compress-code \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{
"code": "def process(items):\n ...",
"language": "">python",
"fidelity": "balanced"
}'Error responses
/v1/batch-compressCompress up to 50 documents in a single call. Documents are processed concurrently (max 4 at once to avoid saturating the embedding model). Each document may have its own fidelity and query. Failed documents are reported inline — the overall batch always returns 200.
Request body
{
"documents": [ // required — 1 to 50 items
{
"text": string, // required
"fidelity": string, // optional, default "balanced"
"query": string|null // optional
}
]
}Response
{
"results": [
{
"compressed": string,
"original_tokens": number,
"compressed_tokens": number,
"savings_pct": number,
"compression_ratio": number,
"error": string|null // set when this document failed; other fields are 0
}
],
"summary": {
"total_documents": number,
"successful": number,
"failed": number,
"total_tokens_in": number,
"total_tokens_saved": number,
"avg_savings_pct": number,
"avg_compression_ratio": number
}
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/batch-compress \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{
"documents": [
{"text": "First document...", "fidelity": "balanced"},
{"text": "Second document...", "query": "neural networks"},
{"text": "Third document...", "fidelity": "outline"}
]
}'Error responses
/v1/recommendAnalyse a document and recommend the optimal fidelity level. Considers document size and (optionally) the target model's context window. Use this to automatically pick the right compression level before calling /compress.
Request body
{
"text": string, // required — document to analyse
"model": string|null, // optional — target model (e.g. "claude-sonnet-4-6")
"context_window": number|null // optional — override context window size in tokens
}Response
{
"recommended_fidelity": string, // e.g. "balanced"
"estimated_ratio": number, // fraction of tokens kept (0.0–1.0)
"estimated_output_tokens": number,
"original_tokens": number,
"reasoning": string // human-readable explanation
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/recommend \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{
"text": "Your long document...",
"model": "claude-sonnet-4-6"
}'API Keys#
Create and manage API keys programmatically. Keys are prefixed gc_ and stored as HMAC-SHA256 hashes. The raw key is returned once on creation and cannot be retrieved again.
/v1/keysCreate a new API key. Returns the full raw key — store it immediately.
Request body
{
"name": string // required — human-readable label (1–100 chars)
}Response
{
"key": string, // full raw key — shown ONCE, store securely
"key_id": string, // 16-char hex ID for management
"name": string,
"created_at": string // ISO 8601 UTC
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/keys \
"color:#fca5a5">-H "Authorization: Bearer YOUR_CLERK_JWT" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{"name": "Production server"}'Error responses
/v1/keysList all API keys for the authenticated user. Returns masked key values — the raw key cannot be retrieved after creation.
Response
{
"keys": [
{
"key_id": string,
"name": string,
"masked_key": string, // e.g. "gc_****ab12"
"created_at": string, // ISO 8601 UTC
"last_used": string|null,
"status": "active" | "revoked"
}
]
}"color:#7dd3fc">curl https://api.gotcontext.ai/v1/keys \
"color:#fca5a5">-H "Authorization: Bearer YOUR_CLERK_JWT"/v1/keys/:idRevoke an API key by ID. Takes effect immediately — the key is rejected by the auth middleware within milliseconds.
Response
{
"success": true,
"key_id": string
}"color:#7dd3fc">curl "color:#fca5a5">-X DELETE https://api.gotcontext.ai/v1/keys/YOUR_KEY_ID \
"color:#fca5a5">-H "Authorization: Bearer YOUR_CLERK_JWT"Error responses
/v1/usageMonthly compression statistics for the authenticated user. Returns compression counts, token totals, plan limit, and the next reset timestamp.
Response
{
"period": string, // "YYYY-MM", e.g. "2026-04"
"compressions_used": number,
"compressions_limit": number, // 1000 (free) or 50000 (pro)
"pct_used": number, // 0.0–100.0
"tokens_in": number, // total original tokens this month
"tokens_saved": number, // total tokens eliminated this month
"resets_at": string // ISO 8601 UTC, midnight 1st of next month
}"color:#7dd3fc">curl https://api.gotcontext.ai/v1/usage \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY"Billing#
Billing is handled by Polar. The checkout and portal endpoints return redirect URLs — do not call these from server-side code without a user session.
/v1/billing/checkoutCreate a Polar checkout session to upgrade to Pro. Returns a URL to redirect the user to.
Request body
{
"plan": "pro" // currently the only valid value
}Response
{
"checkout_url": string // redirect the user to this URL
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/billing/checkout \
"color:#fca5a5">-H "Authorization: Bearer YOUR_CLERK_JWT" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{"plan": "pro"}'Error responses
/v1/billing/portalGet the Polar customer portal URL to manage subscription, payment method, and invoices.
Response
{
"portal_url": string // redirect the user to this URL
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/billing/portal \
"color:#fca5a5">-H "Authorization: Bearer YOUR_CLERK_JWT"Error responses
CLI Filter#
/v1/filter-cliCompress verbose CLI output such as git diffs, test results, and npm install logs. Automatically detects the command type and applies type-specific compression. Typical savings: 80-99% on verbose output.
Request body
{
"output": string, // required — raw CLI output to compress (min 1 char)
"command_hint": string|null // optional — hint: "git_diff", "test_output", etc.
// auto-detected if omitted
}Response
{
"filtered": string, // compressed CLI output
"original_chars": number,
"filtered_chars": number,
"savings_pct": number, // e.g. 92.3
"detected_type": string|null // e.g. "git_diff", "pytest"
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/filter-cli \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{
"output": "diff ">--git a/src/main.py b/src/main.py\n...",
"command_hint": "git_diff"
}'Error responses
Savings#
/v1/savingsRetrieve your cumulative compression savings across all time. Shows total compressions, tokens processed, tokens saved, and an estimated dollar amount saved based on mid-range model pricing.
Response
{
"total_compressions": number,
"total_tokens_in": number,
"total_tokens_saved": number,
"savings_pct": number, // e.g. 87.2
"estimated_cost_saved_usd": number // e.g. 12.45
}"color:#7dd3fc">curl https://api.gotcontext.ai/v1/savings \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY"Error responses
Cache Audit#
/v1/audit-cacheAudit how cache-friendly a prompt is for a specific AI provider. Returns a cacheability score, whether the prompt is cache-friendly, actionable recommendations to improve cache hit rates, and estimated savings.
Request body
{
"text": string, // required — prompt or document text to audit (min 1 char)
"provider": string // optional — "anthropic" | "openai" | "google"
// default: "anthropic"
}Response
{
"provider": string,
"cache_friendly": boolean,
"score": number, // 0.0 - 1.0 cacheability score
"recommendations": [string], // actionable suggestions
"estimated_savings_pct": number // estimated cache hit savings
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/audit-cache \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{
"text": "You are a helpful assistant that...",
"provider": "anthropic"
}'Error responses
Budget Check#
/v1/check-budgetCheck how much of a model's context window a text would consume. Returns token estimates, percentage used, a status indicator (OK / WARNING / CRITICAL), and a recommendation on whether to compress.
Request body
{
"text": string, // required — text to check against budget (min 1 char)
"context_window": number, // optional — target context window in tokens
// default: 200000
"model": string // optional — target model for cost estimation
// default: "claude-opus-4"
}Response
{
"estimated_tokens": number,
"context_window": number,
"pct_used": number, // e.g. 42.5
"status": string, // "OK" | "WARNING" | "CRITICAL"
"recommendation": string // human-readable guidance
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/check-budget \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{
"text": "Your long document or codebase...",
"context_window": 200000,
"model": "claude-opus-4"
}'Error responses
Issue Detection#
/v1/detect-issuesDetect hallucinations and blind spots in compressed output by comparing it against the original text. Finds claims not supported by the source (hallucinations) and critical information that was lost (blind spots). Requires a Pro or Enterprise plan.
Request body
{
"original_text": string, // required — original uncompressed text (min 1 char)
"compressed_text": string, // required — compressed output to check (min 1 char)
"check_hallucination": boolean, // optional — check for hallucinated content
// default: true
"check_blind_spots": boolean // optional — check for lost critical info
// default: true
}Response
{
"issues_found": number,
"issues": [
{
"type": string, // "hallucination" or "blind_spot"
"severity": string, // "low", "medium", or "high"
"description": string,
"location": string|null
}
],
"quality_score": number // 0.0 - 1.0 (1.0 = no issues found)
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/detect-issues \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{
"original_text": "The full original document...",
"compressed_text": "The compressed version...",
"check_hallucination": true,
"check_blind_spots": true
}'Error responses
Error Codes#
All errors return JSON with a detail field describing the problem.
// Example error response
{
"detail": "Invalid fidelity 'garbage'. Valid: ['abstract', 'outline', 'balanced', 'detailed', 'raw']"
}Bad Request
Invalid parameter value (e.g. invalid fidelity, unknown plan, already-revoked key).
Unauthorized
Missing, expired, or invalid Bearer token.
Not Found
Resource not found (e.g. unknown key_id).
Unprocessable Entity
Pydantic validation failed — missing required field or wrong type.
Too Many Requests
Rate limit exceeded. Check the Retry-After header.
Internal Server Error
Unexpected server error. Retry with exponential back-off.
Service Unavailable
Dependency unavailable (Redis, Postgres, or billing service).
Rate Limits#
GET /v1/usage for your current consumption. When you hit the rate limit, the API responds with HTTP 429 and a Retry-After header.Projects#
Organize compression workloads into projects. Each project tracks its own usage stats, making it easy to attribute token savings across teams or applications.
/v1/projectsCreate a compression project.
Request body
{
"name": string, // required — project name (1-100 chars)
"description": string|null // optional — project description
}Response
{
"id": string,
"name": string,
"description": string|null,
"created_at": string,
"stats": { "compressions": 0, "tokens_saved": 0 }
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/projects \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{"name": "backend-docs", "description": "API documentation compression"}'Error responses
/v1/projectsList all projects for the authenticated user.
Response
{
"projects": [
{
"id": string,
"name": string,
"description": string|null,
"created_at": string,
"stats": {
"compressions": number,
"tokens_saved": number
}
}
]
}"color:#7dd3fc">curl https://api.gotcontext.ai/v1/projects \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY"/v1/projects/{id}Get project detail with usage statistics.
Response
{
"id": string,
"name": string,
"description": string|null,
"created_at": string,
"updated_at": string,
"stats": {
"compressions": number,
"tokens_saved": number,
"avg_savings_pct": number
}
}"color:#7dd3fc">curl https://api.gotcontext.ai/v1/projects/YOUR_PROJECT_ID \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY"Error responses
/v1/projects/{id}Update a project's name or description.
Request body
{
"name": string|null, // optional — new name
"description": string|null // optional — new description
}Response
{
"id": string,
"name": string,
"description": string|null,
"updated_at": string
}"color:#7dd3fc">curl "color:#fca5a5">-X PUT https://api.gotcontext.ai/v1/projects/YOUR_PROJECT_ID \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{"name": "backend-docs-v2"}'Error responses
/v1/projects/{id}Delete a project. Compression history is retained but unlinked.
Response
{
"success": true,
"id": string
}"color:#7dd3fc">curl "color:#fca5a5">-X DELETE https://api.gotcontext.ai/v1/projects/YOUR_PROJECT_ID \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY"Error responses
Batch Queue#
Submit large compression jobs asynchronously. The batch queue processes documents in the background and returns results when complete — ideal for bulk ingestion pipelines.
/v1/batch-queueSubmit an async batch compression job. Returns 202 Accepted with a job ID for polling.
Request body
{
"documents": [ // required — 1 to 500 items
{
"text": string, // required
"fidelity": string, // optional, default "balanced"
"query": string|null // optional
}
],
"project_id": string|null, // optional — associate with a project
"webhook_url": string|null // optional — POST results on completion
}Response
{
"job_id": string,
"status": "queued",
"documents_count": number,
"created_at": string
}"color:#7dd3fc">curl "color:#fca5a5">-X POST https://api.gotcontext.ai/v1/batch-queue \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-H "Content-Type: application/json" \
"color:#fca5a5">-d '{
"documents": [
{"text": "First document..."},
{"text": "Second document...", "fidelity": "outline"}
]
}'Error responses
/v1/batch-queueList batch jobs for the authenticated user.
Response
{
"jobs": [
{
"job_id": string,
"status": "queued" | "processing" | "completed" | "failed",
"documents_count": number,
"completed_count": number,
"created_at": string,
"completed_at": string|null
}
]
}"color:#7dd3fc">curl https://api.gotcontext.ai/v1/batch-queue \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY"/v1/batch-queue/{id}Get job status and progress.
Response
{
"job_id": string,
"status": "queued" | "processing" | "completed" | "failed",
"documents_count": number,
"completed_count": number,
"failed_count": number,
"created_at": string,
"completed_at": string|null,
"progress_pct": number // 0.0 - 100.0
}"color:#7dd3fc">curl https://api.gotcontext.ai/v1/batch-queue/YOUR_JOB_ID \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY"Error responses
/v1/batch-queue/{id}/resultsRetrieve completed batch results. Only available when status is 'completed'.
Response
{
"job_id": string,
"results": [
{
"compressed": string,
"original_tokens": number,
"compressed_tokens": number,
"savings_pct": number,
"error": string|null
}
],
"summary": {
"total_documents": number,
"successful": number,
"failed": number,
"total_tokens_saved": number,
"avg_savings_pct": number
}
}"color:#7dd3fc">curl https://api.gotcontext.ai/v1/batch-queue/YOUR_JOB_ID/results \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY"Error responses
Analytics#
Detailed analytics for compression usage across projects. View per-project breakdowns, track trends over time, and export data for reporting.
/v1/analytics/summaryPer-project usage breakdown for the current billing period.
Response
{
"period": string, // "YYYY-MM"
"total_compressions": number,
"total_tokens_saved": number,
"projects": [
{
"project_id": string,
"project_name": string,
"compressions": number,
"tokens_saved": number,
"avg_savings_pct": number
}
]
}"color:#7dd3fc">curl https://api.gotcontext.ai/v1/analytics/summary \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY"Error responses
/v1/analytics/trendsDaily or weekly compression trends. Use query parameters to control the window.
Response
{
"granularity": "daily" | "weekly",
"data": [
{
"date": string, // "YYYY-MM-DD"
"compressions": number,
"tokens_saved": number,
"avg_savings_pct": number
}
]
}"color:#7dd3fc">curl "https://api.gotcontext.ai/v1/analytics/trends?granularity=daily&days=30" \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY"Error responses
/v1/analytics/exportExport analytics data as CSV for the specified date range.
Response
Content-Type: text/csv
date,project,compressions,tokens_in,tokens_saved,savings_pct
2026-04-01,backend-docs,142,284000,248000,87.3
2026-04-01,frontend-app,89,178000,151300,85.0
..."color:#7dd3fc">curl "https://api.gotcontext.ai/v1/analytics/export?start=2026-04-01&end=2026-04-14" \
"color:#fca5a5">-H "Authorization: Bearer YOUR_API_KEY" \
"color:#fca5a5">-o analytics.csvError responses