Frameworks & multi-model workflows
KazenAI enforces budgets on the provider client. Frameworks call that client, so Control means binding the framework to monitored clients and telling the adapter which ones they are.
One budget for the whole workflow
Section titled “One budget for the whole workflow”Each monitor(..., max_budget_usd=...) client has its own cap. A workflow that
plans with an OpenAI model and writes with an Anthropic model has (at least) two
clients, so per-client caps add up. Give them one SharedBudget:
from anthropic import Anthropic, AsyncAnthropicfrom openai import AsyncOpenAI, OpenAIfrom kazenai_finops import SharedBudget, monitor
budget = SharedBudget(max_usd=1.00)planner = monitor(OpenAI(max_retries=0), budget=budget, workflow_id="support-reply")writer = monitor(Anthropic(max_retries=0), budget=budget, workflow_id="support-reply")Every call on either client is checked against the same $1.00 before it is sent,
and the step that would overspend is refused (BudgetExceeded) without reaching
the provider. budget.spent_usd is the workflow total.
SharedBudget covers one process. Across processes or machines, give every
client the same workflow_id and set a workflow limit in Agent FinOps instead.
LangChain
Section titled “LangChain”Bind each chat model to monitored clients. Pass the same budget= to share a cap.
from langchain_anthropic import ChatAnthropicfrom langchain_openai import ChatOpenAIfrom kazenai_finops.adapters.langchain import ( bind_monitored_chat_anthropic, bind_monitored_chat_openai, wrap_langchain_runnable,)
plan_model = ChatOpenAI(model="gpt-4o-mini")bind_monitored_chat_openai(plan_model, OpenAI(max_retries=0), async_client=AsyncOpenAI(max_retries=0), budget=budget)
write_model = ChatAnthropic(model="claude-sonnet-4-6", max_tokens=1024)bind_monitored_chat_anthropic(write_model, Anthropic(max_retries=0), async_client=AsyncAnthropic(max_retries=0), budget=budget)
writer_chain = wrap_langchain_runnable(write_model, capability="control")writer_chain.invoke("Draft a reply to the customer")invoke, stream, ainvoke and astream are all covered. ChatAnthropic
betas are rejected under Control, because beta calls go through
client.beta.messages, which KazenAI does not guard.
For a custom Runnable that calls several monitored clients, declare all of them:
declare_langchain_control_boundary(runnable, planner, writer) and wrap with
guarded_clients=[planner, writer].
LangGraph
Section titled “LangGraph”Declare every provider client the graph’s nodes use, then wrap the compiled graph:
from kazenai_finops.adapters.langgraph import declare_langgraph_control_boundary, wrap_graph
graph = builder.compile()declare_langgraph_control_boundary(graph, planner, writer)app = wrap_graph(graph, capability="control", guarded_clients=[planner, writer])app.invoke({"topic": "refund policy"})A client passed to wrap_graph that the graph did not declare is rejected, so
an unrelated monitored client cannot stand in for the real one. Raw, unmonitored
clients created inside nodes are not intercepted. Checkpoint interrupt/resume
with SqliteSaver is supported.
CrewAI
Section titled “CrewAI”Bind each agent’s native LLM to a monitored client, then wrap the crew with every client it uses:
import anthropic, openaifrom crewai import LLM, Agent, Crew, Taskfrom kazenai import SharedBudgetfrom kazenai_finops.adapters.crewai import bind_crew_llm_client, wrap_crew
researcher = Agent(role="researcher", goal="…", backstory="…", llm=LLM(model="gpt-4o-mini"))writer = Agent(role="writer", goal="…", backstory="…", llm=LLM(model="anthropic/claude-haiku-4-5"))crew = Crew(agents=[researcher, writer], tasks=[...])
budget = SharedBudget(max_usd=1.00)oa = bind_crew_llm_client(researcher, openai.OpenAI(max_retries=0), budget=budget)an = bind_crew_llm_client(writer, anthropic.Anthropic(max_retries=0), budget=budget)
crew = wrap_crew(crew, capability="control", guarded_clients=[oa, an])crew.kickoff() # or: await crew.akickoff()- Each LLM’s sync and async clients share one budget.
- A denial raises
BudgetExceeded, which is also CrewAI’sHookAborted, so CrewAI stops the crew instead of retrying the taskmax_retry_limittimes. wrap_crewrefuses Control when the crew can reach a model KazenAI does not guard: an unbound agent, manager, planning or function-calling LLM, a hierarchical crew without a bound manager LLM, memory, knowledge or embedders,Crew(stream=True),llm_overlay, or a CrewAI LLM class other than native OpenAI / Anthropic (Gemini, Azure, Bedrock, LiteLLM-routed).- Anthropic structured output (
output_pydanticon Claude 4.5+) usesclient.beta.messages, which is not guarded; it is refused before dispatch. - A crew kicked off inside another crew gets its own operation, linked to the
parent by
parent_operation_id. - Cancelling
akickoffstops the crew. CrewAI 1.15 runs agent LLM calls on worker threads, so a call already sent completes and is charged exactly once. await crew.kickoff_async()also works, but it runskickoffon a worker thread that cancellation does not stop: the crew finishes, is charged and emitsworkflow.end. Useakickoffwhen cancelling must stop the crew.
Verified
Section titled “Verified”LangChain 1.4.4 (langchain-openai 1.7.0, langchain-anthropic 1.7.5) and LangGraph
1.2.14 are tested in CI on every change and were verified against the live
OpenAI and Anthropic APIs on 2026-10-12, including a three-model, two-provider
workflow run under one budget until the next step was refused. CrewAI 1.15.26 is
tested in CI on real crews and was verified against the live APIs on 2026-10-13:
kickoff and akickoff on both providers, cancellation, nested crews, and a
two-provider crew on one Agent FinOps workflow budget (one reservation per LLM
call, all settled, then a deny receipt).
