Skip to content

API Reference

CodexA exposes four API surfaces: Python API, REST API, Bridge Protocol, and MCP.

Python API

ToolExecutor

The primary programmatic interface for invoking CodexA tools:

python
from semantic_code_intelligence.tools import ToolExecutor, ToolInvocation

executor = ToolExecutor(project_path=".")
invocation = ToolInvocation(tool_name="semantic_search", arguments={"query": "auth"})
result = executor.execute(invocation)

print(result.success)        # True
print(result.result_payload) # Search results
print(result.execution_time_ms)

Available Tools

ToolArgumentsReturns
semantic_searchquery: str, top_k: intRanked code snippets
explain_symbolsymbol_name: str, file_path: strSymbol explanation
explain_filefile_path: strAll symbols in file
summarize_repo(none)Repository summary
find_referencessymbol_name: strAll references
get_dependenciesfile_path: strImport/dependency map
get_call_graphsymbol_name: strCallers and callees
get_contextsymbol_name: str, file_path: strRich context window

Indexing

python
from semantic_code_intelligence.indexing import run_indexing
from pathlib import Path

result = run_indexing(Path("."))
print(f"Indexed {result.files} files, {result.chunks} chunks")
python
from semantic_code_intelligence.search import hybrid_search

results = hybrid_search("authentication middleware", top_k=10)
for r in results:
    print(f"{r.file}:{r.line} (score: {r.score:.3f})")

Context Building

python
from semantic_code_intelligence.context import ContextBuilder

builder = ContextBuilder(project_path=".")
context = builder.build_context("UserService", max_tokens=4000)
print(context.text)

Quality Analysis

python
from semantic_code_intelligence.ci import run_quality_analysis

report = run_quality_analysis("src/")
print(f"Maintainability: {report.maintainability_index:.1f}")
print(f"Security issues: {len(report.bandit_issues)}")

REST API

Start the web server:

bash
codex web --port 8080

Endpoints

MethodPathDescription
GET/healthServer health and project metadata
GET/api/search?q=&top_k=&threshold=Semantic code search
GET/api/symbols?file=&kind=Symbol table browser
GET/api/deps?file=File dependency graph
GET/api/callgraph?symbol=Call graph edges
GET/api/summaryProject summary
POST/api/askNatural language question
POST/api/analyzeCode validation/explanation

Example

bash
curl "http://localhost:8080/api/search?q=authentication&top_k=5"
json
{
  "results": [
    {
      "file": "src/auth/middleware.py",
      "line": 42,
      "score": 0.89,
      "snippet": "class AuthMiddleware:..."
    }
  ]
}

Bridge Protocol

The bridge provides a stateless JSON/HTTP protocol for IDE extensions:

bash
codex serve --port 24842

Tool Invocation

bash
curl -X POST http://127.0.0.1:24842/tools/invoke \
  -H "Content-Type: application/json" \
  -d '{"tool_name": "semantic_search", "arguments": {"query": "auth"}}'

Bridge Endpoints

MethodPathDescription
GET/Capabilities manifest
GET/healthHealth check
POST/requestHandle an AgentRequest
POST/tools/invokeExecute a tool
GET/tools/listList tools
GET/tools/streamSSE event stream

Request Format

json
{
  "kind": "semantic_search",
  "params": {"query": "authentication", "top_k": 5},
  "request_id": "req-001",
  "source": "copilot"
}

Response Format

json
{
  "success": true,
  "data": {"snippets": [...]},
  "error": "",
  "request_id": "req-001",
  "elapsed_ms": 42.5
}

See the Bridge Reference for the full protocol specification.

MCP (Model Context Protocol)

bash
codex mcp --path /your/project

All 8 tools are exposed via MCP with typed schemas. See MCP Integration for setup instructions.

Released under the MIT License.