Reference
Documentation
Everything you need to index, search, and integrate Optiq into your workflow.
Quickstart
Get up and running in under a minute.
npm install -g @optiqcode/cli optiq login optiq index ~/my-project optiq search "how does auth work"
Installation
Requires Node.js 18 or later.
npm install -g @optiqcode/cli
Verify:
optiq --version
Authentication
Optiq uses device-based authentication. Running optiq login opens your browser where you verify your identity with email OTP and Turnstile captcha.
optiq login
Tokens are stored locally at ~/.optiq/auth.json. They auto-refresh on 401.
optiq whoami # Check current account optiq logout # Clear session
Agent Authentication
AI agents authenticate with Optiq using API keys (Bearer tokens). This guide covers programmatic authentication without browser interaction.
Step 1: Get an API key
Generate an API key from your dashboard. Keys start with sk- and can be scoped to specific permissions.
Step 2: Set the key
Pass the key as a Bearer token in the Authorization header:
curl -X POST https://api.optiqcode.com/api/v1/search \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{"query": "auth middleware", "repo_id": "my-project"}'Or set it as an environment variable for the CLI:
export OPTIQ_API_KEY="sk-your-api-key" optiq search "auth middleware"
Step 3: Scoped permissions
API keys can be scoped to limit access. Request only the permissions your agent needs:
| Scope | Access |
|---|---|
| search:read | Search indexed code |
| repos:read | List repositories |
| repos:write | Index new repositories |
| repos:delete | Delete repositories and indexed data |
| jobs:read | Check indexing job status |
MCP server authentication
The local MCP server (optiq mcp) uses the session from optiq login. The remote MCP endpoint at https://api.optiqcode.com/mcp requires a Bearer token.
OAuth discovery
Authorization server metadata is published at /.well-known/oauth-authorization-server per RFC 8414. Agents can discover endpoints, supported scopes, and PKCE (S256) support automatically.
Indexing
Indexing reads your local files, uploads them to the Optiq engine, and builds a semantic graph with embeddings powered by Voyage AI.
# Index current directory optiq index # Index a specific path optiq index ~/projects/my-app # Force a clean re-index optiq index --fresh
How it works
- CLI collects all source files (skips binaries, node_modules, .git, etc.)
- Files are uploaded to the Optiq API
- Engine parses code with tree-sitter, extracts symbols and relationships
- Voyage AI generates embeddings for semantic search
- A graph of nodes and edges is built for structural retrieval
Incremental indexing
By default, re-indexing only processes changed files. Content fingerprints determine what needs updating. Use --fresh to force a full rebuild.
Auto-reindex (MCP)
When running as an MCP server, Optiq watches indexed directories for file changes and automatically re-indexes in the background with a 3-second debounce.
Embedding requires a Voyage AI API key with a payment method on file (free tier still applies). Add your key in Dashboard > Settings > Provider Keys.
Search
Optiq combines semantic vector search, keyword search (Tantivy), and graph traversal for accurate code retrieval.
Natural language
optiq search "how does the auth middleware validate tokens" optiq search "where are database connections configured"
Structured filters
optiq search "symbol:handleAuth" optiq search "file:middleware type:function" optiq search "def:createUser" optiq search "uses:prisma.user"
Options
| Flag | Description | Default |
|---|---|---|
| --repo-id | Filter by repository | all repos |
| --limit | Max results | 10 |
| --intent | Search intent hint | — |
API Reference
Base URL: https://api.optiqcode.com
Authenticate with Authorization: Bearer <token> or an API key (sk-...).
Query
/api/v1/query{
"query": "how does authentication work",
"repo_id": "my-app-abc12345",
"limit": 10,
"intent": "understand"
}Index files
/api/v1/index-files{
"files": [
{ "path": "src/auth.ts", "content": "..." },
{ "path": "src/db.ts", "content": "..." }
],
"repo_id": "my-app-abc12345",
"embed": true,
"incremental": true,
"fresh": false
}Index status
/api/v1/index/status/{job_id}List repositories
/api/v1/reposDelete repository
/api/v1/repos/{repo_id}Rate Limits
Every API response includes rate limit headers so agents can self-throttle and avoid getting blocked.
Response headers
| Header | Description |
|---|---|
| X-RateLimit-Limit | Maximum requests allowed per window |
| X-RateLimit-Remaining | Requests remaining in current window |
| X-RateLimit-Reset | Unix timestamp when the window resets |
| Retry-After | Seconds to wait before retrying (on 429 responses) |
Limits by tier
| Plan | Search | Index | Window |
|---|---|---|---|
| Free | 100/day | 10/day | 24h rolling |
| Pro | Unlimited | Unlimited | 1min sliding |
| Enterprise | Custom | Custom | Custom |
Handling 429 responses
When rate limited, the API returns HTTP 429 with a Retry-After header. Agents should wait the specified number of seconds before retrying. Implement exponential backoff for repeated 429s.
Streaming
For long-running operations like indexing large repositories, the API supports Server-Sent Events (SSE) for real-time progress updates.
Streaming index progress
Add Accept: text/event-stream to receive SSE updates during indexing:
curl -N -H "Authorization: Bearer sk-your-key" \
-H "Accept: text/event-stream" \
https://api.optiqcode.com/api/v1/repos
# SSE events:
# event: progress
# data: {"files_processed": 42, "files_total": 100, "status": "indexing"}
#
# event: complete
# data: {"repo_id": "abc123", "status": "ready", "files_indexed": 100}Streaming search
Search results can be streamed as they are ranked. Each event contains a single result:
curl -N -H "Authorization: Bearer sk-your-key" \
-H "Accept: text/event-stream" \
-H "Content-Type: application/json" \
-d '{"query": "auth middleware", "stream": true}' \
https://api.optiqcode.com/api/v1/search
# event: result
# data: {"file_path": "src/auth.ts", "score": 0.92, ...}
#
# event: done
# data: {"total": 8, "query_time_ms": 340}Error Handling
All errors return structured JSON with a machine-readable code, human-readable message, and a resolution hint.
Error format
{
"error": {
"code": "invalid_request",
"message": "Missing required field: query",
"hint": "Include a 'query' string in the request body"
}
}HTTP status codes
| Status | Code | When | Recovery |
|---|---|---|---|
| 400 | invalid_request | Malformed request body or missing fields | Check the hint field and fix the request |
| 401 | unauthorized | Missing or invalid API key | Check your API key at /dashboard/api-keys |
| 403 | forbidden | Key lacks required scope | Generate a key with the needed scope |
| 404 | not_found | Repository or job not found | Verify the ID exists and is indexed |
| 429 | rate_limited | Too many requests | Wait for Retry-After seconds, then retry |
| 500 | internal_error | Server error | Retry with backoff; check /status |
MCP error responses
The MCP server returns standard JSON-RPC 2.0 errors with structured codes:
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32602,
"message": "Invalid params: 'query' is required",
"data": { "hint": "Pass a non-empty query string" }
}
}MCP Server
The CLI doubles as an MCP (Model Context Protocol) server over stdio. AI agents can index, search, and manage repositories through it.
optiq mcp
Exposed tools
| Tool | Description |
|---|---|
| optiq_index | Index a directory — reads files and uploads for indexing |
| optiq_search | Search indexed code with natural language |
| optiq_status | Check indexing job status |
| optiq_repos | List all indexed repositories |
Auto-reindex
After the first optiq_index call, the MCP server watches the directory for changes and incrementally re-indexes in the background (3s debounce).
Integrations
Claude Code
claude mcp add optiq -- optiq mcp
Cursor
// .cursor/mcp.json
{
"mcpServers": {
"optiq": {
"command": "optiq",
"args": ["mcp"]
}
}
}Claude Desktop
// claude_desktop_config.json
{
"mcpServers": {
"optiq": {
"command": "optiq",
"args": ["mcp"]
}
}
}Any MCP client
Any client supporting stdio transport works. Point it at optiq mcp.
CLI Reference
| Command | Description |
|---|---|
| optiq login | Sign in via device auth |
| optiq logout | Sign out |
| optiq whoami | Show current account |
| optiq index [path] | Index a directory |
| optiq index --fresh | Full re-index from scratch |
| optiq search <query> | Search indexed code |
| optiq search --repo-id <id> | Search specific repo |
| optiq repos | List repositories |
| optiq status <job_id> | Check indexing status |
| optiq mcp | Start MCP server |
Need help? [email protected] · npm · Dashboard tutorial