Add an HTTP API to Microsoft GraphRAG with FastAPI

Add an HTTP API to Microsoft GraphRAG with FastAPI

Kimi Lu

Abstract background with a sophisticated and elegant feel, featuring a blend of soft, diffused colors like blues, purples, and golds. The colorful, blurry…

Add an HTTP API to Microsoft GraphRAG with FastAPI

Microsoft GraphRAG ships a CLI and Python API, but not a production HTTP service. To expose it over HTTP, load one fixed GraphRAG project, keep its index tables in memory for queries, and run expensive indexing as a controlled background job. Do not accept an arbitrary filesystem path from each request.

This guide uses GraphRAG's current graphrag.api interface with FastAPI. It provides three endpoints:

  • POST /index starts an index build and returns immediately.

  • GET /index/status reports the current job state.

  • POST /query runs a global search against the latest loaded index.

1. Create and Initialize the Project

GraphRAG currently requires Python 3.10–3.12. Create a virtual environment and install the dependencies:

Create a GraphRAG workspace:

Add your provider configuration to rag/settings.yaml and the required secret to rag/.env. Put source documents in rag/input/, then build the first index:

The official GraphRAG quickstart explains model configuration and warns that indexing can consume substantial LLM resources. Start with a small dataset.

2. Add the FastAPI Service

Create api.py beside the rag directory:

This example fixes the GraphRAG project root in server configuration. That avoids a path-traversal bug in which a caller could ask the service to index or read an arbitrary server directory.

3. Run the API

Start Uvicorn from the directory containing api.py:

Keep it bound to 127.0.0.1 during development. If another service or user must reach it, add an authenticated proxy instead of exposing the development server directly.

4. Start and Monitor Indexing

Start a rebuild:

Check its state:

A successful run reloads the Parquet tables so later queries use the new index. The process keeps the previous in-memory tables available while a rebuild runs.

5. Query GraphRAG

Send a JSON request rather than putting the question in a URL:

The example uses global search. GraphRAG also offers local, DRIFT, and basic query methods; choose the method that matches the question and load the tables required by that API.

Production Checklist

Before deploying this service:

  1. Add authentication and authorization to every endpoint.

  2. Move indexing to a durable job queue if the process may restart or you need more than one worker.

  3. Store job state outside process memory.

  4. Limit request size, query length, concurrency, and model spend.

  5. Separate read traffic from index writes and switch index versions atomically.

  6. Redact secrets and sensitive document text from logs.

  7. Pin and test the GraphRAG version; its configuration and APIs can change between releases.

An HTTP endpoint is only the service boundary. If AI clients need portable discovery and tool schemas, read MCP vs API before deciding whether to expose the same operation through MCP as well.

Sources

Home

Home

Home

Integrations

Integrations

Integrations

Vault

Vault

Vault

Audit

Audit

Audit

Arana Grande

Arana Grande

Arana Grande

Free

Free

Free

30-day audit summary

30-day audit summary

30-day audit summary

Daily action-call volume and the latest receipts from the Loadout audit trail.

Daily action-call volume and the latest receipts from the Loadout audit trail.

Daily action-call volume and the latest receipts from the Loadout audit trail.

View Audit

View Audit

View Audit

Loadout usage

Loadout usage

Loadout usage

617 action calls in the last 30 days

617 action calls in the last 30 days

617 action calls in the last 30 days

May 19 - Jun 17

May 19 - Jun 17

May 19 - Jun 17

10 active days

10 active days

10 active days

Less

Less

Less

More

More

More

Recent activity

Recent activity

Recent activity

Latest action-call receipts from connected agents

Latest action-call receipts from connected agents

Latest action-call receipts from connected agents

Apr 23, 09:23 AM

Apr 23, 09:23 AM

Apr 23, 09:23 AM

Shopify

Shopify

Shopify

Creates Or Updates An Asset For A Theme

Creates Or Updates An Asset For A Theme

Creates Or Updates An Asset For A Theme

Success

Success

Success

Apr 23, 09:21 AM

Apr 23, 09:21 AM

Apr 23, 09:21 AM

Shopify

Shopify

Shopify

Update Products Param Product Id

Update Products Param Product Id

Update Products Param Product Id

Success

Success

Success

Apr 23, 08:53 AM

Apr 23, 08:53 AM

Apr 23, 08:53 AM

Shopify

Shopify

Shopify

Update Products Param Product Id

Update Products Param Product Id

Update Products Param Product Id

Failed

Failed

Failed

Apr 22, 22:13 PM

Apr 22, 22:13 PM

Apr 22, 22:13 PM

Shopify

Shopify

Shopify

Create Product Image

Create Product Image

Create Product Image

Success

Success

Success

Apr 22, 22:12 PM

Apr 22, 22:12 PM

Apr 22, 22:12 PM

Shopify

Shopify

Shopify

Create Product Image

Create Product Image

Create Product Image

Success

Success

Success

Connected integration coverage

Connected integration coverage

Connected integration coverage

162

162

162

of 753 accessible connected

of 753 accessible connected

of 753 accessible connected

Callable actions

Callable actions

Callable actions

1,126

1,126

1,126

Vault credentials

Vault credentials

Vault credentials

8

8

8

Explore what's possible

Explore what's possible

Explore what's possible

See all Integrations

See all Integrations

See all Integrations

Google Ads

Google Ads

Google Ads

All available Goolge Ads tools via...

All available Goolge Ads tools via...

All available Goolge Ads tools via...

X (twitter)

X (twitter)

X (twitter)

All available X tools via...

All available X tools via...

All available X tools via...

Github

Github

Github

All available Github tools via...

All available Github tools via...

All available Github tools via...

Notion

Notion

Notion

All available Notion tools via...

All available Notion tools via...

All available Notion tools via...

Slack

Slack

Slack

All available Slack tools via...

All available Slack tools via...

All available Slack tools via...

Firecrawl

Firecrawl

Firecrawl

All available Firecrawl tools via...

All available Firecrawl tools via...

All available Firecrawl tools via...

753 integrations are available for loadouts.

753 integrations are available for loadouts.

753 integrations are available for loadouts.

Plug your entire stack into your AI agents.

Plug your entire stack into your AI agents.

Plug your entire stack into your AI agents.

Skip the integration headache. Plug 750+ tools into Claude Code, Codex, and OpenClaw in one go, and let your agents execute today.

Skip the integration headache. Plug 750+ tools into Claude Code, Codex, and OpenClaw in one go, and let your agents execute today.