{ }

Reference

Documentation

Everything you need to index, search, and integrate Optiq into your workflow.


Quickstart

Get up and running in under a minute.

bash
npm install -g @optiqcode/cli
optiq login
optiq index ~/my-project
optiq search "how does auth work"

Installation

Requires Node.js 18 or later.

bash
npm install -g @optiqcode/cli

Verify:

bash
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.

bash
optiq login

Tokens are stored locally at ~/.optiq/auth.json. They auto-refresh on 401.

bash
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:

bash
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:

bash
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:

ScopeAccess
search:readSearch indexed code
repos:readList repositories
repos:writeIndex new repositories
repos:deleteDelete repositories and indexed data
jobs:readCheck 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.

bash
# 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

  1. CLI collects all source files (skips binaries, node_modules, .git, etc.)
  2. Files are uploaded to the Optiq API
  3. Engine parses code with tree-sitter, extracts symbols and relationships
  4. Voyage AI generates embeddings for semantic search
  5. 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.



API Reference

Base URL: https://api.optiqcode.com

Authenticate with Authorization: Bearer <token> or an API key (sk-...).

Query

POST/api/v1/query
json
{
  "query": "how does authentication work",
  "repo_id": "my-app-abc12345",
  "limit": 10,
  "intent": "understand"
}

Index files

POST/api/v1/index-files
json
{
  "files": [
    { "path": "src/auth.ts", "content": "..." },
    { "path": "src/db.ts", "content": "..." }
  ],
  "repo_id": "my-app-abc12345",
  "embed": true,
  "incremental": true,
  "fresh": false
}

Index status

GET/api/v1/index/status/{job_id}

List repositories

GET/api/v1/repos

Delete repository

DELETE/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

HeaderDescription
X-RateLimit-LimitMaximum requests allowed per window
X-RateLimit-RemainingRequests remaining in current window
X-RateLimit-ResetUnix timestamp when the window resets
Retry-AfterSeconds to wait before retrying (on 429 responses)

Limits by tier

PlanSearchIndexWindow
Free100/day10/day24h rolling
ProUnlimitedUnlimited1min sliding
EnterpriseCustomCustomCustom

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:

bash
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:

bash
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

json
{
  "error": {
    "code": "invalid_request",
    "message": "Missing required field: query",
    "hint": "Include a 'query' string in the request body"
  }
}

HTTP status codes

StatusCodeWhenRecovery
400invalid_requestMalformed request body or missing fieldsCheck the hint field and fix the request
401unauthorizedMissing or invalid API keyCheck your API key at /dashboard/api-keys
403forbiddenKey lacks required scopeGenerate a key with the needed scope
404not_foundRepository or job not foundVerify the ID exists and is indexed
429rate_limitedToo many requestsWait for Retry-After seconds, then retry
500internal_errorServer errorRetry with backoff; check /status

MCP error responses

The MCP server returns standard JSON-RPC 2.0 errors with structured codes:

json
{
  "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.

bash
optiq mcp

Exposed tools

ToolDescription
optiq_indexIndex a directory — reads files and uploads for indexing
optiq_searchSearch indexed code with natural language
optiq_statusCheck indexing job status
optiq_reposList 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

bash
claude mcp add optiq -- optiq mcp

Cursor

json
// .cursor/mcp.json
{
  "mcpServers": {
    "optiq": {
      "command": "optiq",
      "args": ["mcp"]
    }
  }
}

Claude Desktop

json
// 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

CommandDescription
optiq loginSign in via device auth
optiq logoutSign out
optiq whoamiShow current account
optiq index [path]Index a directory
optiq index --freshFull re-index from scratch
optiq search <query>Search indexed code
optiq search --repo-id <id>Search specific repo
optiq reposList repositories
optiq status <job_id>Check indexing status
optiq mcpStart MCP server