- 01
Keep the event stream for per-node detail
Stream events and read usage on on_chat_model_end if you want tokens per node in your own traces. That view is still useful. It is a record of calls that already happened.
- 02
Point the model at Fuse
Use the OpenAI chat model with the Fuse base URL and a Fuse key. Claude and Gemini model names work too when those models are switched on; Fuse picks the stored provider key from the model id.
graph.pyimport os from langchain_openai import ChatOpenAI model = ChatOpenAI( model="gpt-4.1-mini", base_url="https://fuse.ospalabs.com/v1", api_key=os.environ["FUSE_API_KEY"], max_tokens=1024, ) - 03
Tag the graph and the user
Pass x-fuse-tag with the graph or node name and x-fuse-user with an opaque id. The Features and Customers pages then split spend without a separate aggregator.
- 04
Treat 402 as the end of the run
Catch the API error in the node that calls the model and end the graph. Retrying a 402 only produces more 402s until the period resets or you raise the ceiling.
Track LangGraph token usage, then stop it at a dollar ceiling
Updated November 2026
LangGraph can stream events while a graph runs. on_chat_model_end carries usage_metadata for that call: input tokens, output tokens, and sometimes cache reads. Add them up across nodes and you know what a run consumed. You still need a price list, a place to store the totals, and a decision to make before the next call goes out.
Token counts arrive after the provider has answered, so they explain a bill. They do not stop the node that is about to exceed it. Point the chat model at Fuse. Each call is priced first, logged with its tokens and cost, and refused with 402 when the ceiling would be crossed.
Questions
Does the event stream include dollars?
It includes token counts from the model response. Dollars are a price times those counts. Fuse stores the priced cost on each request; the stream can still feed your own traces.
Will a checkpointed graph resume after 402?
Only if you resume it after the ceiling resets or is raised. The next model call is refused for as long as the reservation would cross the limit.