dspy-cli scaffolds DSPy programs and serves them as HTTP APIs. dspy-cli new creates a project that can hold many programs, each a task with its own DSPy signature and module; dspy-cli serve discovers the modules, stands up a FastAPI server with one auto-generated endpoint and web form per program, and writes an OpenAPI definition at /openapi.json.
Creating a project runs an interactive flow that names the first program, picks a module type — Predict, ChainOfThought, ProgramOfThought, ReAct, MultiChainComparison, or Refine — and takes a signature such as blog_post -> summary or post:str -> tags:list[str], category:str. Further programs are added with dspy-cli generate scaffold -s " ", which writes a signature file under src/ /signatures and a module file under src/ /modules. Each call is logged to a program-specific JSONL file under logs.
Models are declared in dspy.config.yaml as a registry keyed by LiteLLM-style identifiers, with maxtokens, temperature, modeltype, an optional apibase for a locally hosted endpoint, and an env name pointing at the API key in the project's .env. A default key sets the project-wide model and a programmodels map overrides it per program.
Features
- Standard project layout: signatures, modules, and shared utilities each get their own package directory, and serve discovers programs from the modules folder
- Auto-generated endpoints: each module becomes a route named after it, callable from the browser form or directly over HTTP
- Type validation: typed parameters and return values declared on a module's forward method are validated during API calls
- Hot reloading: editing a signature or module definition reloads the server and updates the served programs
- OpenAPI spec generation: every serve run writes a JSON OpenAPI definition served at /openapi.json
- MCP server: passing --mcp to serve exposes the programs as Model Context Protocol tools
- Per-program models: a model registry plus a program_models map routes individual programs to different providers or a local endpoint
- Container config: new writes a Dockerfile alongside the project
