- Overview
- Getting Started
- Authentication
- REST API Endpoints
- GraphQL API
- WebSocket Support
- Error Handling
- Rate Limiting
- Security
- Monitoring
The GraphRAG API Service provides a comprehensive interface for graph-based retrieval-augmented generation, supporting both REST and GraphQL APIs with enterprise-grade features.
- Production:
https://api.graphrag.example.com - Staging:
https://staging.graphrag-api.example.com - Local Development:
http://localhost:8001
- Current Version: v1
- Supported Versions: v1
- Deprecation Policy: 6-month notice before deprecation
# Using curl
curl -X GET http://localhost:8001/health
# Using httpie
http GET localhost:8001/health
# Using Python requests
import requests
response = requests.get("http://localhost:8001/health")# Get authentication token
curl -X POST http://localhost:8001/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "user", "password": "pass"}'
# Use token in requests
curl -X GET http://localhost:8001/api/workspaces \
-H "Authorization: Bearer YOUR_TOKEN"The API uses JWT (JSON Web Tokens) for authentication.
POST /api/auth/login
Content-Type: application/json
{
"username": "string",
"password": "string"
}Response:
{
"access_token": "eyJ...",
"token_type": "bearer",
"expires_in": 3600
}Include the token in the Authorization header:
Authorization: Bearer YOUR_ACCESS_TOKENFor service-to-service communication:
X-API-Key: YOUR_API_KEYGET /healthReturns basic health status.
Response:
{
"status": "healthy",
"timestamp": "2025-09-02T12:00:00Z",
"uptime": 3600.5,
"version": "0.1.0",
"environment": "production"
}GET /health/detailedReturns comprehensive health information including system metrics.
GET /health/liveKubernetes liveness probe endpoint.
GET /health/readyKubernetes readiness probe endpoint.
GET /health/metricsReturns Prometheus-compatible metrics.
GET /api/workspacesQuery Parameters:
limit(int): Maximum number of results (default: 10)offset(int): Pagination offset (default: 0)
Response:
{
"workspaces": [
{
"id": "uuid",
"name": "My Workspace",
"description": "Workspace description",
"status": "active",
"created_at": "2025-09-02T12:00:00Z",
"updated_at": "2025-09-02T12:00:00Z"
}
],
"total": 1,
"limit": 10,
"offset": 0
}POST /api/workspaces
Content-Type: application/json
{
"name": "New Workspace",
"description": "Description",
"data_path": "/path/to/data",
"chunk_size": 1200,
"max_entities": 1000
}GET /api/workspaces/{workspace_id}PUT /api/workspaces/{workspace_id}
Content-Type: application/json
{
"name": "Updated Name",
"description": "Updated description"
}DELETE /api/workspaces/{workspace_id}?remove_files=falsePOST /api/query
Content-Type: application/json
{
"workspace_id": "uuid",
"query": "What is the main topic?",
"query_type": "global",
"parameters": {
"temperature": 0.7,
"max_tokens": 500
}
}Response:
{
"response": "The main topic is...",
"sources": [
{
"document": "doc1.txt",
"relevance": 0.95
}
],
"metadata": {
"processing_time": 1.23,
"tokens_used": 450
}
}POST /api/index
Content-Type: application/json
{
"workspace_id": "uuid",
"documents": [
{
"path": "/path/to/document.txt",
"content": "Document content...",
"metadata": {}
}
],
"options": {
"chunk_size": 1200,
"overlap": 100
}
}GET /api/index/status/{job_id}POST /graphql
type Query {
workspace(id: ID!): Workspace
workspaces(limit: Int, offset: Int): WorkspaceList
queryGraph(input: QueryInput!): QueryResponse
systemInfo: SystemInfo
healthCheck: HealthStatus
}
type Mutation {
createWorkspace(input: CreateWorkspaceInput!): Workspace
updateWorkspace(id: ID!, input: UpdateWorkspaceInput!): Workspace
deleteWorkspace(id: ID!): DeleteResponse
indexDocuments(input: IndexInput!): IndexResponse
clearCache(namespace: String): ClearCacheResponse
}
type Subscription {
indexingProgress(jobId: ID!): IndexingProgress
queryProgress(queryId: ID!): QueryProgress
}query GetWorkspace($id: ID!) {
workspace(id: $id) {
id
name
description
status
statistics {
documentCount
entityCount
relationshipCount
}
}
}mutation CreateWorkspace($input: CreateWorkspaceInput!) {
createWorkspace(input: $input) {
id
name
status
}
}subscription IndexingProgress($jobId: ID!) {
indexingProgress(jobId: $jobId) {
progress
currentStep
totalSteps
message
}
}const ws = new WebSocket("ws://localhost:8001/ws")
ws.onopen = () => {
ws.send(
JSON.stringify({
type: "subscribe",
channel: "indexing",
jobId: "job-123",
})
)
}
ws.onmessage = (event) => {
const data = JSON.parse(event.data)
console.log("Progress:", data.progress)
}{
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input parameters",
"details": {
"field": "workspace_id",
"reason": "Workspace not found"
},
"timestamp": "2025-09-02T12:00:00Z",
"request_id": "req-123"
}
}200 OK: Success201 Created: Resource created204 No Content: Success with no response body400 Bad Request: Invalid input401 Unauthorized: Authentication required403 Forbidden: Access denied404 Not Found: Resource not found429 Too Many Requests: Rate limit exceeded500 Internal Server Error: Server error503 Service Unavailable: Service temporarily unavailable
VALIDATION_ERROR: Input validation failedAUTHENTICATION_ERROR: Authentication failedAUTHORIZATION_ERROR: Insufficient permissionsRESOURCE_NOT_FOUND: Requested resource not foundRATE_LIMIT_EXCEEDED: Too many requestsINTERNAL_ERROR: Internal server errorSERVICE_UNAVAILABLE: Service temporarily unavailable
- Anonymous: 100 requests per minute
- Authenticated: 1000 requests per minute
- API Key: 5000 requests per minute
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1693584000
Retry-After: 60{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded",
"retry_after": 60
}
}The API includes the following security headers:
X-Content-Type-Options: nosniffX-Frame-Options: DENYX-XSS-Protection: 1; mode=blockStrict-Transport-Security: max-age=31536000; includeSubDomainsContent-Security-Policy: default-src 'self'
CORS is configured for specific origins:
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Authorization, Content-Type
Access-Control-Max-Age: 3600- All data is encrypted in transit (TLS 1.3)
- Sensitive data is encrypted at rest
- PII is automatically redacted from logs
- SQL injection protection enabled
- Input validation on all endpoints
GET /health/metricsgraphrag_up: Application status (1=up, 0=down)graphrag_uptime_seconds: Application uptimegraphrag_request_duration_seconds: Request duration histogramgraphrag_request_total: Total requests countergraphrag_active_connections: Active connection gaugegraphrag_memory_usage_bytes: Memory usagegraphrag_cpu_percent: CPU usage percentage
All requests are logged with:
- Request ID
- User ID (if authenticated)
- IP Address
- Response time
- Status code
- Error details (if applicable)
Distributed tracing is available with OpenTelemetry:
X-Trace-ID: 1-5e1b3c4d-6f7a8b9c0d1e2f3a4b5c6d7e
X-Span-ID: a1b2c3d4e5f6g7h8from graphrag_client import GraphRAGClient
client = GraphRAGClient(
base_url="http://localhost:8001",
api_key="your-api-key"
)
# Create workspace
workspace = client.create_workspace(
name="My Workspace",
description="Test workspace"
)
# Query
response = client.query(
workspace_id=workspace.id,
query="What is the main topic?",
query_type="global"
)
print(response.text)import { GraphRAGClient } from "@graphrag/client"
const client = new GraphRAGClient({
baseUrl: "http://localhost:8001",
apiKey: "your-api-key",
})
// Create workspace
const workspace = await client.createWorkspace({
name: "My Workspace",
description: "Test workspace",
})
// Query
const response = await client.query({
workspaceId: workspace.id,
query: "What is the main topic?",
queryType: "global",
})
console.log(response.text)Use the following endpoints for testing:
/api/test/echo: Echoes back the request/api/test/delay/{seconds}: Delays response by specified seconds/api/test/error/{code}: Returns specified error code
Import the Postman collection from:
/docs/postman/graphrag-api.postman_collection.json
Access the OpenAPI spec at:
http://localhost:8001/openapi.json
- Documentation: https://docs.graphrag-api.example.com
- GitHub Issues: https://github.com/pierregrothe/graphrag-api/issues
- Email Support: support@graphrag-api.example.com
- Status Page: https://status.graphrag-api.example.com
Last Updated: 2025-09-02 API Version: 1.0.0