Skip to main content
Infrahub provides multiple API interfaces to interact with your infrastructure data, each optimized for different use cases.

Available APIs

GraphQL API

The primary API for querying and mutating infrastructure data. GraphQL provides:
  • Flexible querying with nested relationships
  • Schema introspection
  • Real-time subscriptions via WebSockets
  • Branch-aware operations
  • Time-travel queries with the at parameter
Endpoint: /graphql/{branch_name} See GraphQL API for detailed documentation.

REST API

The REST API provides endpoints for specific operations:
  • Artifact management
  • File operations
  • Schema retrieval
  • Diff operations
  • Stored query execution
Base URL: /api See REST API for detailed documentation.

Python SDK

The official Python SDK provides a high-level interface for:
  • Type-safe operations
  • Object-oriented access to nodes and relationships
  • Async/await support
  • Automatic authentication handling
Install via pip:
pip install infrahub-sdk
Example usage:
from infrahub_sdk import InfrahubClient

client = InfrahubClient(url="http://localhost:8000", token="your-api-token")

# Query nodes
devices = await client.all(kind="InfraDevice")

# Create a node
device = await client.create(
    kind="InfraDevice",
    name="router-01",
    location="datacenter-1"
)
await device.save()

API Features

Branch Support

All APIs support Git-like branching for isolated changes:
  • Query data from specific branches
  • Make changes in feature branches
  • Merge branches with conflict detection

Time-Travel Queries

Query historical data using the at parameter:
  • Absolute timestamps: 2024-01-15T10:30:00Z
  • Relative times: -1h, -7d, -30m

Authentication

All authenticated endpoints support:
  • JWT tokens (access and refresh)
  • API keys
  • OAuth 2.0 (Google, custom providers)
  • OIDC (OpenID Connect)
See Authentication for detailed information.

Interactive Documentation

Infrahub provides interactive API documentation:
  • Swagger UI: /api/docs - Interactive REST API documentation
  • ReDoc: /api/redoc - Alternative REST API documentation
  • GraphQL Playground: Available at the GraphQL endpoint for interactive query building

API Versioning

The API version is returned in the /api/info endpoint:
curl http://localhost:8000/api/info \
  -H "Authorization: Bearer <token>"
Response:
{
  "deployment_id": "550e8400-e29b-41d4-a716-446655440000",
  "version": "0.15.0"
}

Error Handling

GraphQL Errors

GraphQL returns errors in the response alongside data:
{
  "data": null,
  "errors": [
    {
      "message": "Node not found",
      "path": ["InfraDevice"],
      "extensions": {
        "code": "NODE_NOT_FOUND"
      }
    }
  ]
}

REST API Errors

REST endpoints use standard HTTP status codes:
  • 200 - Success
  • 400 - Bad Request
  • 401 - Unauthorized
  • 403 - Forbidden
  • 404 - Not Found
  • 422 - Validation Error
  • 500 - Internal Server Error
Error response format:
{
  "errors": ["Detailed error message"]
}

Next Steps

Build docs developers (and LLMs) love