Skip to main content
dagraph separates the concept of a backend (how to reach a provider) from the model (which model to call). A backend is the transport layer — it knows how to authenticate, send a request, and parse the response for a specific provider. You set a default backend once with the --backend CLI flag; individual nodes can override it by prefixing the model name with a provider identifier.

Backend summary

Backend details

The claude_code backend spawns claude -p as a subprocess for each node call. It runs against your Claude Code plan (Max or Pro) rather than the API, so nodes do not accrue per-token API charges. Token usage is still recorded in traces and counted against any budget you set (using equivalent API cost), but the charges are your plan subscription, not pay-per-token.
The claude_code backend starts a new, isolated claude session per node call with no persistent tools. Streaming (stream: true on a node) is silently ignored for this backend.
The api backend calls the Anthropic Messages API directly. It supports all agent node features including tools, mcp_servers, output_schema, and stream.Setup: Set ANTHROPIC_API_KEY in your environment or in a .env file at your project root.
The openai backend calls the OpenAI Chat Completions API.Setup: Set OPENAI_API_KEY in your environment or .env.
Use the openai/ prefix to route a specific node to OpenAI regardless of the default backend:
The gemini backend calls the Google GenAI API.Setup: Set GEMINI_API_KEY in your environment or .env.
The bedrock backend calls AWS Bedrock. It requires the [bedrock] extra and AWS credentials configured in your environment (via AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, an IAM role, or an AWS profile).Setup:
The ollama backend sends requests to a locally running Ollama daemon on localhost:11434. No API key is required. Use this as a free last resort in a fallback_chain, or as the default backend for development.Setup: Install and start Ollama, then pull the models you need:
The codex backend spawns the OpenAI Codex CLI as a subprocess, similar to how claude_code spawns the claude CLI. It runs against your OpenAI plan.Setup: Install and authenticate the codex CLI.

Model-prefix routing

Any node can be pinned to a specific backend by prefixing the model value with provider/. dagraph splits on the first /, resolves the backend, and passes the remainder to that backend’s SDK.
Examples: Supported prefixes: anthropic, openai, gemini, bedrock, ollama. An unknown prefix raises a validation error at run time.
Mix models from different providers in a single DAG. Route cheap fast nodes to Haiku or ollama/llama3.2, send quality-sensitive nodes to claude-sonnet-4-6, and pin any node that needs structured output to anthropic/claude-sonnet-4-6 (the only backend that supports output_schema).

Setting the default backend

Use the --backend flag with agentgraph run. Every node that does not have a provider prefix in its model field uses this default.
Nodes with a model prefix always override the default:

Fallback chains

Every agent node (and the generator/evaluator roles inside composite nodes) accepts a fallback_chain: an ordered list of model strings to try when the primary model returns a retriable error.
Retriable errors (walk the chain): HTTP 429, 5xx, network errors, timeouts. Non-retriable errors (bypass the chain immediately): HTTP 401/403 (auth errors) and HTTP 400/422 (bad request). A different provider cannot fix bad credentials or invalid inputs. The scheduler tries each entry in order. The first model to return a successful response wins. Cost is charged only for the successful attempt. Every attempt — including failed ones — is recorded in the trace so you can see which provider actually served the response.

Multi-provider example

The following example (from examples/multi_provider_fallback.yaml) shows two nodes each using a different primary provider with a fallback chain:
Run it with: