Budgets for Direct Provider Calls
Griptape Cloud enforces spending budgets on every call that goes through the Griptape proxy. A node that calls a model provider directly, for example with the user's own OpenAI or Anthropic key, bypasses the proxy, so Cloud never sees the call. Two requests let such a node take part in budgets anyway:
BudgetAccessRequest, sent before the call, asks Cloud whether the call fits the budgets of the open project.ReportUsageRequest, sent after the call, tells Cloud what the call cost, so it counts against those budgets and shows in usage auditing.
The engine adds the project, workflow, engine and session to both requests for you. Send the provider's own name for the model, such as gpt-5-nano, in both requests, so a refusal and the spend it would have been are grouped under the same model in usage audits. Pass the node's class name as node_type. node_id is for an opaque id; never pass the node's name, which the user types and may not want shared.
Before the call: BudgetAccessRequest
from griptape_nodes.retained_mode.events.budget_events import (
BudgetAccessRequest,
BudgetAccessResultFailure,
)
from griptape_nodes.retained_mode.griptape_nodes import GriptapeNodes
check = await GriptapeNodes.ahandle_request(
BudgetAccessRequest(
model="gpt-5-nano",
estimated_cost_micro_usd=40_000,
node_type=type(self).__name__,
)
)
if isinstance(check, BudgetAccessResultFailure):
raise check.exception
- In
aprocess(),await GriptapeNodes.ahandle_request(...)as shown, so the engine keeps running while the check waits on Griptape Cloud. In a synchronousprocess(), callGriptapeNodes.handle_request(...)instead. - A failure means a budget refused the call. Do not make it. Raise
check.exception: the run stops with a message naming the node and every budget that refused, and the editor shows its "Run blocked" bar. - A success means go ahead.
checkedisFalsewhen Cloud could not be reached or no Griptape Cloud credential is set; the call is still cleared. A network problem must never stop work. estimated_cost_micro_usdis optional. Without it, only a budget with no headroom left refuses the call.
After the call: ReportUsageRequest
Report the token counts the provider returned. Griptape Cloud prices them, so your node never needs a price table.
from griptape_nodes.retained_mode.events.budget_events import ReportUsageRequest
await GriptapeNodes.ahandle_request(
ReportUsageRequest(
input_tokens=1_000,
output_tokens=500,
cache_read_tokens=900,
provider="openai",
model="gpt-5-nano",
activity_type="chat_completion",
node_type=type(self).__name__,
correlation_id=check.correlation_id,
)
)
-
input_tokensis the total prompt token count, cached tokens included.cache_read_tokensis the cached share of it, andcache_write_tokensthe tokens written to the cache. Leave either out when the provider doesn't report it. Providers report the total differently:Provider input_tokenscache_read_tokenscache_write_tokensOpenAI prompt_tokensprompt_tokens_details.cached_tokensprompt_tokens_details.cache_write_tokensAnthropic input_tokens+cache_read_input_tokens+cache_creation_input_tokenscache_read_input_tokenscache_creation_input_tokensBedrock (Converse) inputTokens+cacheReadInputTokens+cacheWriteInputTokenscacheReadInputTokenscacheWriteInputTokensAnthropic and Bedrock leave the cached tokens out of their input count, so passing their input count alone reports too little, and Griptape Cloud rejects a report whose cache counts exceed it.
-
When the call took audio in, also send
input_audio_tokens, the audio share ofinput_tokenswith cached audio included, andcache_audio_read_tokens, the cached share of that audio. The cached audio is also counted incache_read_tokens. OpenAI reports input audio asprompt_tokens_details.audio_tokens. Leave both out for a call without audio. -
If your node runs its model through pydantic-ai, pass its
RunUsagecounts straight across, audio included:RunUsage.input_tokensis already the total for every provider, andinput_audio_tokensandcache_audio_read_tokensfollow the same rules. -
modelis required with token counts, because Griptape Cloud prices by model. Send the same provider name for the model as in the check. -
Token counts are priced as chat completions. For a chat call, leave
activity_typeout or set it tochat_completion. For any other kind of call, senddeclared_cost_micro_usdinstead. -
If your node knows its cost but has no token counts, send
declared_cost_micro_usd(in millionths of a US dollar) instead. Send one or the other, never both. -
The report is sent in the background and returns at once. It is retried briefly, then dropped with a line in the engine log.
-
Never fail a node over its report. Ignore the result. A report with neither token counts nor a declared cost, or with both, comes back as a failure with the reason. Griptape Cloud checks everything else, such as the model or the cache counts, and a report it rejects is logged and dropped. Either way the node carries on.
-
Pass the
correlation_idfrom the check's success so Cloud can pair the check with the report.