Integrations Overview
Cycles has integration patterns for LLM providers, agent frameworks, and web servers. The guides show where to place reserve → execute → commit/release around protected paths. Coverage depends on the hooks and calls each integration actually instruments; uninstrumented traffic is unaffected.
Supported integrations
| Integration | Language | Streaming | Pattern |
|---|---|---|---|
| LLM Providers | |||
| OpenAI (Python) | Python | Yes | Decorator |
| OpenAI (TypeScript) | TypeScript | Yes | withCycles / reserveForStream |
| Anthropic (Python) | Python | Yes | Decorator |
| Anthropic (TypeScript) | TypeScript | Yes | withCycles / reserveForStream |
| AWS Bedrock | TypeScript | Yes | withCycles / reserveForStream |
| Google Gemini | TypeScript | Yes | withCycles / reserveForStream |
| Groq | Python / TypeScript | — | Decorator / withCycles |
| Ollama / Local LLMs | Python / TypeScript | — | Decorator / withCycles |
| AI Frameworks | |||
| LangChain | Python | Yes | Agent middleware (langchain-runcycles) — CyclesModelGate + CyclesToolGate + CyclesFanOutGate for create_agent; callback handler for non-agent runnables |
| LangChain.js | TypeScript | Yes | Callback handler |
| LangGraph | Python | — | Agent middleware (langchain-runcycles) for create_agent nodes; callback handler / decorator for raw StateGraph |
| Vercel AI SDK | TypeScript | Yes | reserveForStream |
| Spring AI | Java | Yes | @Cycles annotation |
| LlamaIndex | Python | — | Decorator |
| CrewAI | Python | — | Decorator |
| Pydantic AI | Python | — | Decorator |
| AnyAgent | Python | — | Callback (lifecycle hooks) |
| AutoGen | Python | — | Model client wrapper |
| Agent Platforms | |||
| MCP Server | TypeScript (Node.js) | — | MCP tools |
| OpenAI Agents | Python | — | RunHooks (lifecycle hooks) |
| OpenClaw | TypeScript | Yes | Plugin (lifecycle hooks) |
| AP2 (Agent Payments Protocol) | Python | — | Payment-mandate guard (runcycles-ap2) — reserve / commit / release around AP2 mandates; Cycles idempotency deduplicates accounting, while PSP idempotency or an atomic claim is still required for consume-once execution |
| Runtime SDKs | |||
| Rust | Rust | Yes | Tokio async client + RAII guards |
| Web Frameworks | |||
| Next.js | TypeScript | Yes | withCycles / Middleware |
| Express | TypeScript | Yes | Middleware / withCycles |
| Django | Python | — | Middleware / Decorator |
| Flask | Python | — | Decorator / before_request |
| FastAPI | Python | — | Middleware / Decorator |
Integration patterns
Cycles offers several integration approaches depending on your stack:
MCP Server
The zero-code tool-exposure approach. Add the Cycles MCP Server to your AI agent's configuration and it discovers cycles_reserve, cycles_commit, and other budget tools through MCP. This is cooperative, not automatic enforcement of the host's other actions. Hard limits require Cycles Budget Guard for Claude Code or a mandatory handler, gateway, harness, or service boundary.
Best for: budget-aware workflows and discovery in Claude Desktop, Claude Code, Cursor, Windsurf, and other MCP-compatible hosts.
Decorator / Higher-order function
The simplest approach. Wrap your LLM-calling function and Cycles handles reservation, commit, and release automatically.
- Python:
@cyclesdecorator - TypeScript:
withCycleshigher-order function
Best for: individual model calls, simple request-response flows.
RunHooks / Lifecycle hooks
For agent frameworks that expose lifecycle hooks. A plugin implements the framework's hook interface to create reservations on start and commit on end — covering the entire agent run automatically.
- OpenAI Agents SDK:
CyclesRunHooksimplements the SDK'sRunHooksinterface - OpenClaw: Plugin hooks into
before_model_resolve,before_tool_call, etc.
Best for: multi-agent workflows, tool governance, agent handoff tracking.
Agent middleware (LangChain 1.x)
For LangChain agents built with langchain.agents.create_agent. The langchain-runcycles package provides AgentMiddleware subclasses (CyclesModelGate, CyclesToolGate, CyclesFanOutGate) that intercept model calls, tool calls, and model turns before execution — denial returns a ToolMessage so the agent recovers gracefully, and fan-out can be capped at the model-turn level.
Best for: production LangChain agents, anything using create_agent, agent-style LangGraph nodes.
Callback handler
For agent frameworks like LangChain that fire events on every LLM call. A custom callback handler creates reservations on llm_start and commits on llm_end.
Best for: bare LangChain runnables (ChatOpenAI / chains / RAG), non-agent LangGraph nodes, multi-turn agents on the legacy bind_tools flow without create_agent.
reserveForStream
For streaming responses where the actual cost is only known after the stream completes. Reserves budget upfront, auto-extends the reservation TTL during streaming, and commits actual usage when the stream finishes.
Best for: streaming chat UIs, Vercel AI SDK, any provider with streaming support.
Programmatic client
Direct access to the Cycles client for full control over the reservation lifecycle. Use when the higher-level patterns don't fit your architecture.
Best for: custom frameworks, complex orchestration, batch processing.
See Choosing the Right Integration Pattern for detailed guidance.
Adding a new integration
All integrations follow the same protocol:
- Reserve budget before the LLM call with an estimated cost
- Execute the model call (respecting any caps returned)
- Commit actual cost from token usage after execution
- Release on error to free held budget
See Using the Cycles Client Programmatically for the full client API reference.
Webhook & Observability Integrations
Cycles emits webhook events for budget state changes, reservation denials, tenant lifecycle, and more. Connect to external alerting and incident management systems:
| Integration | Use Case | Guide |
|---|---|---|
| PagerDuty | On-call incident response for budget exhaustion and over-limit | Webhook Integrations |
| Slack | Channel notifications for budget thresholds and tenant alerts | Webhook Integrations |
| ServiceNow | Incident creation for critical budget events | Webhook Integrations |
| Custom receiver | Direct HTTP endpoint with HMAC verification | Webhook Integrations |
See Webhook Integrations for full examples with signature verification code in Python, Node.js, and Go.
Next steps
- Adding Cycles to an Existing Application — step-by-step guide for your first integration
- Webhook Integrations — PagerDuty, Slack, ServiceNow webhook examples
- Cost Estimation Cheat Sheet — pricing reference for estimation
- Error Handling Patterns — handling budget errors across languages
Read the foundations
For the layer-by-layer view of where these integrations sit relative to other agent control approaches — wrappers, provider-client patches, framework hooks, LLM gateways, observability — and why runtime authority complements them rather than replaces them:
- Python AI Agent Control: Cost, Risk, and Audit by Layer — six layers walked through, what each covers across cost / risk / audit, and where each stops short.
- How Cycles Meters Caller-Assigned Action Exposure — how applications combine tool authorization with caller-assigned
RISK_POINTSat instrumented boundaries. - Why Local-First Agent Runtimes Need Runtime Authority — local-first / BYOK category context for OpenClaw, Cline, Aider, Continue, and similar runtimes.
- Agents Are Cross-Cutting. Your Controls Aren't. — the structural argument for why agent governance has to span every integration the agent uses.