Run the API Server
In shortStart the 10xGraph development server with 10xgraph dev, and run it in production with the Gunicorn image from 10xgraph build.
- 6 min read
- 10 sections
- Updated
- v1.0.0
- Markdown
10xgraph dev runs the same API server that production runs, locally, with reload on. This page covers running it for development and in production. This guide covers running the server for development and production, configuring it, and troubleshooting deployment issues.
For a production setup see the production checklist; stopping the server without losing runs is covered in Graceful shutdown.
Prerequisites
Verify that your project has a valid 10xgraph.json config file and a graph module that can be imported:
# Check the config file
cat 10xgraph.json
# Verify the graph module exists and is importable
python -c "from graph.react import app; print(app)"Both commands must succeed without errors. If they fail, see Configure the server for the config format and Project setup to scaffold a new project.
Development: start the server
From the folder containing 10xgraph.json, run the server with auto-reload enabled:
10xgraph dev --no-openThe server binds to http://127.0.0.1:8000 and restarts whenever you edit any Python file. This is the fastest way to iterate on your graph locally. Auto-reload is the default; to disable it, pass --no-reload.
10xgraph dev opens the hosted playground in your browser once the API responds. Pass --no-open to start the server only, as above. To open the playground, leave the flag out:
10xgraph devFlags: --config/-c, --host/-H, --port/-p, --reload/--no-reload, --open/--no-open, --verbose/-v and --quiet/-q. The commands 10xgraph api and 10xgraph play were removed before 1.0; use 10xgraph dev.
Run 10xgraph dev against Docker backends
When Postgres, Redis or Qdrant run in Docker Compose and 10xgraph dev runs on your host, the host reaches them through published ports. Publish each port on 127.0.0.1 only, so nothing else on your network can connect:
services:
postgres:
image: postgres:17-alpine
ports:
- "127.0.0.1:5432:5432"
redis:
image: redis:7-alpine
ports:
- "127.0.0.1:6379:6379"
qdrant:
image: qdrant/qdrant:latest
ports:
- "127.0.0.1:6333:6333"
- "127.0.0.1:6334:6334"In .env, use localhost as the host, not the compose service names. postgres, redis and qdrant resolve only inside the Docker network, that is, for a container of the same compose project:
# On the host (10xgraph dev)
DATABASE_URL=postgresql://<user>:<password>@localhost:5432/<database>
REDIS_URL=redis://:<password>@localhost:6379/0
QDRANT_URL=http://localhost:6333
# Inside a container on the compose network
# DATABASE_URL=postgresql://<user>:<password>@postgres:5432/<database>If the URLs still use a service name, the startup check fails at boot and names the unreachable host:port. See Backend unreachable at startup.
Verify the server is running
Open another terminal and ping the server to confirm it is reachable:
curl http://127.0.0.1:8000/pingExpected response:
{"data": "pong", "metadata": {"request_id": "...", "timestamp": "...", "message": "OK"}}The /ping endpoint requires no authentication and is designed for health checks (load balancers, monitoring systems).
Explore the API with interactive docs
When running locally, the server exposes interactive API documentation that lets you test endpoints without writing code. Open either of these in your browser:
- Swagger UI (recommended):
http://127.0.0.1:8000/docs - ReDoc (alternative):
http://127.0.0.1:8000/redocs
Both show the full endpoint list, parameters, request/response shapes, and authentication requirements. You can click “Try it out” on any endpoint to test it directly.
Example: invoke the graph
- Open
http://127.0.0.1:8000/docs - Find the
POST /v1/graph/invokeendpoint and expand it - Click “Try it out”
- In the request body, enter sample input:
{
"messages": [{"role": "user", "content": [{"type": "text", "text": "Hello"}]}]
}Leave config out. The server starts a new thread and returns its id in data.meta.thread_id. By default it refuses a thread_id that does not exist yet.
- Click “Execute”
You will see the full response, including the graph’s output, any tool calls, and messages. This is the best way to understand your API’s behavior.
Development options and flags
Bind to a different host or port
By default, the server binds to 127.0.0.1:8000. To accept connections from other machines (e.g., in Docker or on a network), bind to 0.0.0.0:
10xgraph dev --no-open --host 0.0.0.0 --port 8000To use a different port:
10xgraph dev --no-open --port 8001Environment variables and config file
Your graph may require environment variables (API keys, database URLs, Redis, etc.). Load them from a .env file by specifying the path in 10xgraph.json:
{
"agent": "graph.react:app",
"env": ".env"
}Or pass them directly to the shell:
export GOOGLE_API_KEY=your_key
export REDIS_URL=redis://localhost:6379
10xgraph dev --no-openTo use a non-default config file:
10xgraph dev --no-open --config config/staging.jsonThis is useful when you have separate configs for dev, staging, and production.
Logging verbosity
Enable verbose output for debugging (shows request details, node execution times, checkpointer operations):
10xgraph dev --no-open --verboseOr suppress all output except errors:
10xgraph dev --no-open --quietDisable API documentation
The interactive docs (/docs and /redocs) expose your endpoint structure. If you want to hide them (often a production concern), set the env vars before starting:
export DOCS_PATH=""
export REDOCS_PATH=""
10xgraph dev --no-open --no-reloadWhen MODE=production, these paths default to empty unless explicitly set. In other modes, they are enabled by default.
Production: deploy with Docker and workers
The 10xgraph dev command runs a development server only (single Uvicorn worker with file watching). It is not suitable for production traffic. Production runs Gunicorn with Uvicorn workers inside the image that 10xgraph build generates.
For production, generate a Docker setup with multiple workers and production configuration:
10xgraph build --docker-composeThis creates:
Dockerfilewith production layers and multi-worker setupdocker-compose.yml(with--docker-compose) for easy local testing of the built imagek8s.yaml(with--k8s) for Kubernetes deployment
The generated Dockerfile runs the app via Gunicorn with Uvicorn workers. The worker count comes from WEB_CONCURRENCY (the Dockerfile sets it to 2; override it at run time) and the graceful shutdown timeout is raised so in-flight runs can finish.
To build and test locally:
docker build -t my-agent:latest .
docker run -p 8000:8000 my-agent:latestSet required environment variables:
docker run -e JWT_SECRET_KEY=your_secret -e WEB_CONCURRENCY=4 -p 8000:8000 my-agent:latestSee Deploy the server for the complete production guide, Kubernetes setup, and deployment checklist.
Troubleshooting
Port already in use
If Address already in use appears, either choose a different port or kill the process holding the current port:
# Use a different port
10xgraph dev --no-open --port 8001
# Or find and kill the process on port 8000
lsof -ti :8000 | xargs kill -9Graph import fails: “ModuleNotFoundError”
The server cannot import your graph module. Check:
- Verify the import path in
10xgraph.jsonis correct (format:"module:attribute") - Verify the module is installed or on the Python path
- Test manually:
python -c "from graph.react import app"
If still failing, check that the project root is in sys.path and that all dependencies are installed.
Environment variable is not set
If you see an error like "GOOGLE_API_KEY" not set, either export it before starting:
export GOOGLE_API_KEY=your_value
10xgraph dev --no-openOr add it to a .env file and configure 10xgraph.json:
{
"agent": "graph.react:app",
"env": ".env"
}Ensure .env contains the variable and is in the project root.
Requests are slow
Check whether the slowness is in the server or your graph:
# Enable verbose logging
10xgraph dev --no-open --verboseLook at the logs to see if the server itself is slow (networking, checkpointer reads) or if the graph is slow (tool execution, model latency). Check:
- Does your graph make external API calls? Test those connections.
- Is a tool taking a long time? Check its implementation and any external services it calls.
- Is the checkpointer slow? Verify database connectivity and load.
“Connection refused” or cannot reach the server
Confirm that:
- The server is running (check the terminal where you started it)
- The host and port are correct (default:
http://127.0.0.1:8000) - In Docker or on a VM, networking is properly configured (ensure
--host 0.0.0.0and the port is exposed)
Test with: curl http://127.0.0.1:8000/ping
If the server itself exits at boot with Refusing to start: ... backend(s) unreachable, a configured Postgres, store or cache store (Redis) is down or its URL is wrong. See Backend unreachable at startup.
Next steps
- Configure the server: See Configure the server for auth, checkpointing, rate limiting, and per-environment settings.
- Deploy to production: See Deploy the server for Docker, Kubernetes, and production hardening.
- Monitor and debug: See Observability for logs, metrics, tracing, and error handling.
- Call the server from code: See Invoke and stream for REST endpoint details, and TypeScript client for client library usage.
Frequently asked questions
- Can I use 10xgraph dev in production?
- No. The 10xgraph dev command runs a single-worker development server with reload. There is no separate production command. For production, use Docker with Gunicorn and multiple Uvicorn workers. Generate production files with 10xgraph build --docker-compose.
- How do I check if the server is running?
- Call the /ping endpoint via curl. It returns a JSON object with success true and data pong, and requires no authentication.
- Why does my server restart when I save a file?
- Auto-reload is enabled by default in development. Files are watched and the server reloads when any Python file changes. Disable it with --no-reload.