Serve and inspect
In shortStart the 10xGraph API server with 10xgraph dev, test it with curl, read thread state over REST and inspect your agent's behavior in the hosted playground.
- 5 min read
- 8 sections
- Updated
- v1.0.0
- Markdown
So far, you have built and tested an agent locally in Python. To use it from a web application or share it across a team, you need to expose it as an HTTP API. The 10xGraph API server serves your compiled graph as a FastAPI app.
In this step, you will start the API server from the agent and memory you built in step 3, test it with curl, read thread state over REST, and use the hosted playground for interactive testing.
Prerequisites
Install the server and a provider extra:
pip install 10xgraph-api "10xgraph[google-genai]"The server loads a project folder, so scaffold one with 10xgraph init (the Quickstart explains each file). Copy .env.example to .env and set your provider API key:
mkdir tutorial-server && cd tutorial-server
10xgraph init --mode quick --name tutorial-server --provider google
cp .env.example .envThe server needs a graph compiled with a checkpointer and exposed as app. Replace the contents of graph/agent.py with the weather graph from step 2, compiled with the checkpointer from step 3:
from dotenv import load_dotenv
from tenxgraph.core.graph import Agent, StateGraph, ToolNode
from tenxgraph.core.state import AgentState
from tenxgraph.storage.checkpointer import InMemoryCheckpointer
from tenxgraph.utils import END
load_dotenv()
def get_weather(location: str) -> str:
"""Get the current weather for a specific location."""
return f"The weather in {location} is sunny and 22°C."
tool_node = ToolNode([get_weather])
checkpointer = InMemoryCheckpointer()
agent = Agent(
model="google/gemini-2.5-flash",
system_prompt=[
{
"role": "system",
"content": "You are a helpful assistant. Use tools when you need specific information.",
}
],
tool_node="TOOL",
)
graph = StateGraph(AgentState)
graph.add_node("MAIN", agent)
graph.add_node("TOOL", tool_node)
def route(state: AgentState) -> str:
if not state.context:
return END
last = state.context[-1]
if hasattr(last, "tools_calls") and last.tools_calls and last.role == "assistant":
return "TOOL"
return END
graph.add_conditional_edges("MAIN", route, {"TOOL": "TOOL", END: END})
graph.add_edge("TOOL", "MAIN")
graph.set_entry_point("MAIN")
app = graph.compile(checkpointer=checkpointer)The 10xgraph.json that init wrote already points to this graph at graph.agent:app: the app variable in graph/agent.py.
Start the API server
From the folder containing 10xgraph.json, run:
10xgraph dev --no-open --host 127.0.0.1 --port 800010xgraph dev is the development server: it reloads when your files change. --no-open starts the server without opening the hosted playground. For production, 10xgraph build writes a Dockerfile (and a compose file with --docker-compose).
Uvicorn logs show the server listening on http://127.0.0.1:8000. The exact log lines vary by version.
Explore the API in Swagger UI
Open the Swagger UI at http://127.0.0.1:8000/docs. You will see every endpoint the server exposes, grouped by tag. Each endpoint shows its request and response schema, so you can test directly in the browser.
Check server health with a simple endpoint:
curl http://127.0.0.1:8000/pingResponse (the metadata values vary per request):
{"data":"pong","metadata":{"request_id":"...","timestamp":"...","message":"OK"}}Test the graph with invoke
The /v1/graph/invoke endpoint executes the graph end-to-end and returns the final messages. Open a second terminal and send:
curl -X POST http://127.0.0.1:8000/v1/graph/invoke \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": [{"type": "text", "text": "What is the weather in Paris?"}]}]
}'The request body takes messages and optional config, initial_state, recursion_limit (default 25) and response_granularity. By default the response lists the messages produced by this run, each with message_id, role and a content array of typed blocks (abbreviated here):
{
"data": {
"messages": [
{"role": "assistant", "content": [{"type": "text", "text": "The weather in Paris is sunny and 22°C."}]}
],
"thread_id": "7f3c2a10-5b1e-4c9a-9d2e-1a2b3c4d5e6f",
"run_id": "...",
"meta": {"thread_id": "7f3c2a10-5b1e-4c9a-9d2e-1a2b3c4d5e6f", "is_new_thread": true}
},
"metadata": {"request_id": "...", "timestamp": "...", "message": "OK"}
}The request had no thread_id, so the server started a new thread, picked its id and returned it in data.thread_id. Send that id back as config.thread_id to continue the thread and test memory. By default the server refuses an id that does not exist (404), so use the id it returned instead of making one up. Replace THREAD_ID with the id from your response:
curl -X POST http://127.0.0.1:8000/v1/graph/invoke \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": [{"type": "text", "text": "What did I ask about first?"}]}],
"config": {"thread_id": "THREAD_ID"}
}'The agent remembers your first question because the checkpointer loaded the earlier messages.
Full details are in the API reference.
Stream responses with stream
For real-time feedback, use /v1/graph/stream. The server sends one JSON object per line. Each object is a StreamChunk with an event field (message, state, updates or error):
curl -X POST http://127.0.0.1:8000/v1/graph/stream \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": [{"type": "text", "text": "What is the weather in London?"}]}]
}' | head -20Output (abbreviated; each line is a separate JSON object, and the fields inside message are the same as in the invoke response):
{"event":"message","message":{"role":"assistant","delta":true,"content":[...]},"thread_id":"7f3c2a10-5b1e-4c9a-9d2e-1a2b3c4d5e6f",...}
...Chunks with "delta": true are partial text. The streaming format is useful for chatbots and real-time UIs where you display tokens as they arrive.
Read thread state over REST
You can inspect any thread you own without invoking the graph again. Use the thread id from the invoke response in place of THREAD_ID. The GET /v1/threads/{thread_id}/state endpoint returns the saved state:
curl http://127.0.0.1:8000/v1/threads/THREAD_ID/stateResponse:
{
"data": {
"state": {
"context": [ ...all saved messages, oldest first... ],
"context_summary": null,
"execution_meta": { ... }
}
},
"metadata": {...}
}Custom fields from your AgentState subclass appear next to context. To list only the messages, call GET /v1/threads/THREAD_ID/messages.
Test interactively with the playground
The hosted playground gives you a chat UI without writing frontend code. 10xgraph dev opens it by default once the API responds. Stop the running server first, then start it without --no-open:
10xgraph dev --host 127.0.0.1 --port 8000The browser opens automatically once the API responds (if not, copy the URL from the terminal). The playground connects to your local API and shows a chat interface.
In the playground, you can:
- Send messages: type naturally. Each message calls
POST /v1/graph/streamorPOST /v1/graph/invoke, depending on the mode you pick. - See tool calls: if the agent uses tools, you see what was called and the result.
- Inspect raw traffic: open the request log to see the frames exchanged with the API.
- Test multiple threads: create a new conversation to start a fresh thread.
Try the same questions:
What is the weather in Tokyo?
What about London?
What did I ask first?The last question tests memory. The playground keeps the same thread_id within a conversation, so the checkpointer restores context.
Next step
Call the server from a TypeScript application using the 10xGraph client, Call from your app.