Eve
Track provider costs and priced tools in Eve agents.
The orbytelabs/eve integration uses one hook to check credits before model and
tool execution, then track reported inference usage and successful priced tools.
Streaming and non-streaming calls use the same usage events.
Video tutorial
Install
Add the integration to an existing Eve project. Eve is an optional peer of Orbyte; other SDK imports do not require it.
npm install orbytelabs eve@^1.0.0 ai@^7.0.172Define billing in the catalog
import { credits, defineConfig } from "orbytelabs";
import { eveFeatures } from "orbytelabs/eve";
export default defineConfig({
features: eveFeatures(credits.markup("25%"), {
weather: credits("0.02"),
}),
});The weather key matches agent/tools/weather.ts. Omitted or zero-priced tools
are free. Connection tools use the full name Eve reports. Names that cannot be
Orbyte feature keys, including qualified names such as github.createIssue, get
stable hashed keys. Grants cover deployed inference and priced tools by default,
including tools added in later deployments.
Deploy the catalog and fund the authenticated customer before running the agent.
Use the principal ID your Eve authentication supplies, shown here as user_123:
npx orbytelabs login
npx orbytelabs link
npx orbytelabs deploy
npx orbytelabs grant 5 --identity user_123 \
--idempotency-key eve_example_user_123
npx orbytelabs api-key create --name "Eve example"Set ORBYTE_API_KEY to the key's one-time secret on your Eve server. Configure
model credentials through Eve as usual. Keep API keys on the server.
Install the billing hook
Create one file in Eve's hooks directory:
import { creditHooks } from "orbytelabs/eve";
export default creditHooks({
identity: ({ session }) => session.auth.current?.principalId,
onError: async (error, event, ctx) => {
console.error("Eve billing failed", {
error: error.message,
event: event.type,
operation: ctx.occurrence.idempotencyKey,
session: ctx.session.id,
});
},
});identity receives Eve's hook context and can be asynchronous. Resolve the
customer from authenticated server data, such as the current principal or an
application lookup for its organization. A missing or invalid identity stops
work before checking credits. The approved identity is retained for tracking,
so a later context change cannot switch the customer charged for that work.
The hook awaits check on model.started and call.started, including when an
approved tool resumes. A denied check or failed check request stops execution.
It tracks model expense on usage.recorded and successful tools on
call.settled. Omitted and zero-priced tools execute without a charge.
Inference checks require 0.001 eligible credits by default. Set
inferenceMinimumBalance to change that starting threshold. Checks reserve no
funds, so the final charge can still fail if the operation costs more than the
remaining balance or concurrent work spends it.
The example logs post-execution billing failures. Persist them for reconciliation
in your application. The onError callback receives the error, original event,
and Eve context, and is awaited. If it throws, Eve's normal hook failure behavior
applies.
Install the hook in each local subagent whose usage you bill. Resolve its customer
from trusted application data, using ctx.session.parent?.rootSessionId when you
need the root session's billing account. Parent agent calls, skill loads, control
calls and delegated usage records do not add duplicate charges. A remote agent
needs its own billing setup.
Inference pricing
Eve's reported USD cost maps to one credit per dollar before the catalog's
markup. A $0.004 call with 25% markup costs 0.005 credits and records
costUsdInNanos: 4_000_000n. Costs round up to nano dollars. Zero-cost calls record
explicit zero usage and expense.
For model-specific prices, pass a map of requested model IDs and an optional
default:
eveFeatures(
{
"openai/gpt-6-luna": credits.markup("25%"),
default: credits.markup("10%"),
},
{ weather: credits("0.02") },
);A configured model rule takes precedence. Insufficient credits never select a cheaper fallback. Model rules create hashed feature keys; include those keys in the customer's grants.
The default expense is event.data.usage.costUsd, which Eve derives from the
provider's reported cost. If it is absent, supply inferenceCost(event, modelId).
Return that usage record's USD expense as a decimal string or number. Token counts
are available in event.data.usage; modelId is the model selected before
execution. Apply the customer markup in the deployed catalog. Missing or invalid
costs report a billing failure instead of charging zero.
Billing boundaries
The hook bills the model usage Eve records, including spend for discarded answers and failed runs when the provider reported billable usage. A usage record can combine several provider calls. It does not bill delegated usage again in the parent session. Successful priced tools produce one count event. Rejected, failed and interrupted tools produce no tool charge.
Eve does not retry failed hooks. A process crash can prevent tracking or failure
reporting. Persist unresolved billing failures and reconcile them through your
application's existing job or outbox mechanism. This integration has no durable
delivery queue or automatic retry. A cancelled stream may have no final usage
report. Direct invokeTool calls outside conversations bypass session hooks and
need application checks and tracking.
Stable billing keys derive from the session and Eve's hook occurrence key.
Retry an uncertain charge with track using its original identity, feature,
payload, cost, and key. Recovery after billing state is released needs application
reconciliation. Do not add AI SDK billing or manually track the same operations
alongside this hook.
