Skip to main content

Serve any LangGraph graph over the OpenAI Chat Completions + Responses APIs.

Project description

GraphServe

GraphServe is an open-source Python library that serves any LangGraph graph over the OpenAI Chat Completions and Responses APIs, enabling seamless integration of agent workflows into OpenAI-compatible applications.

Installation

pip install graphserve

Quickstart

from fastapi import FastAPI
from langgraph.graph import StateGraph, START, END
from graphserve import GraphRegistry, GraphConfig, create_openai_router

# 1. Build your LangGraph graph
graph = StateGraph(...)
# ... add nodes and edges ...
compiled = graph.compile()

# 2. Register it under a model name
registry = GraphRegistry()
registry.register("my-agent", GraphConfig(graph=compiled))

# 3. Mount the OpenAI-compatible router on your FastAPI app
app = FastAPI()
app.include_router(create_openai_router(registry), prefix="/v1")

Your app now exposes:

Route Description
GET /v1/models List registered graphs
POST /v1/responses Create a response (streaming or non-streaming)
GET /v1/responses/{id} Retrieve a previous response
DELETE /v1/responses/{id} Delete a response
POST /v1/chat/completions Chat Completions API

Public API

Export Description
GraphRegistry Registry mapping model names to graph configs
GraphConfig Holds a single already-compiled graph to serve
create_openai_router Builds a FastAPI APIRouter with all OpenAI-compatible routes

create_openai_router options

create_openai_router(
    registry,   # GraphRegistry — required
)

GraphServe is a pure OpenAI↔LangGraph converter. Cross-cutting concerns are the consumer's job, applied with standard tools:

  • Auth — apply it where you mount the router:
    app.include_router(create_openai_router(registry), prefix="/v1",
                       dependencies=[Depends(verify_api_key)])
    
  • Callbacks / tracing — attach to your graph when you build it.

Per-request runtime context is derived generically from the OpenAI request and exposed to the graph as LangGraph runtime context: usercontext["user_id"], instructionscontext["metadata"]["custom_instructions"], and metadata is passed through as context["metadata"]. Graphs read what they need and ignore the rest.

Stateful responses and previous_response_id

All state is managed through the registered graph's LangGraph checkpointer, keyed by thread_id. If a graph is compiled without a checkpointer, GraphServe automatically injects an InMemorySaver (with a warning). Response IDs encode the model (resp_<model>.<hex>) so GET/DELETE routes can resolve the owning graph without any external metadata store.

To use a persistent checkpointer:

from langgraph.checkpoint.memory import MemorySaver
compiled = graph.compile(checkpointer=MemorySaver())

Streaming

Pass "stream": true in the request body to receive Server-Sent Events following the OpenAI Responses API event schema (response.created, response.output_item.added, response.output_text.delta, response.completed, etc.).

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphserve-0.1.1.tar.gz (118.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphserve-0.1.1-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file graphserve-0.1.1.tar.gz.

File metadata

  • Download URL: graphserve-0.1.1.tar.gz
  • Upload date:
  • Size: 118.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for graphserve-0.1.1.tar.gz
Algorithm Hash digest
SHA256 784a2a0f1ce54689bbc76a8eb4ecf5f086937ae7e156eef0a751c76e367938f8
MD5 d660f774de3b8d6c3f421b1a82758064
BLAKE2b-256 de1aff6f447a14c48a4eb1a5036cac76037022114a312d33ab6f5fd70e18194a

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphserve-0.1.1.tar.gz:

Publisher: ci.yml on AndrewNgo-ini/graphserve

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file graphserve-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: graphserve-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for graphserve-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 278327bbae377058ec9e26149d8aa21688d07faf4d85bb1228faba38ef8b10ab
MD5 3642784d973849c11e35879d8445ac95
BLAKE2b-256 c8d8c51ee3c8a62adddb2c2d98370dc1cfcdda6b4bbc230c3126f4db2bbfa614

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphserve-0.1.1-py3-none-any.whl:

Publisher: ci.yml on AndrewNgo-ini/graphserve

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page