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.2.tar.gz (126.5 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.2-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: graphserve-0.1.2.tar.gz
  • Upload date:
  • Size: 126.5 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.2.tar.gz
Algorithm Hash digest
SHA256 168659fe8114aa96ed7cdc821ebe3eb22ded983189c396b91a9e0cd8c6ba7158
MD5 a0ce07c90772eb81d8e307e1a5fa8e52
BLAKE2b-256 f77b489f0f23594d15f3ccf758049118ef58fdce85629f5110ab5b48e67f5007

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphserve-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: graphserve-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 23.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8adc942a0c9edeb428d8f5f2d0dbe9751d23be993f8c441d5e52edaa69c75adc
MD5 6fe1fa014698b3dc5dd75dc2a887bce2
BLAKE2b-256 7a9c1c90fd3a7a11bb2d795766ebc0a5557847958dcfa6fd9d03a6e560f59af5

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphserve-0.1.2-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