Skip to main content
In this guide, you’ll build an agent that researches the latest TypeScript release and reports what it found, its sources, and the tool cost.
Import the helper and add it to your agent’s tools:

Before you start

This example asks the agent to spend up to $0.10 on one tool call. Model charges are separate. Set an application spending limit if you need a hard cap; the prompt alone doesn’t enforce one.This example cannot collect payment confirmation. Configure your account for unattended purchases before running it. This setting also affects your personal agents.
1

Install

In a new directory, create an ESM project and install the integration:
2

Set your keys

Set both keys in your terminal:
No browser sign-in is needed. Keep both keys on your server and out of source control.
3

Create your agent

Save this as agent.ts:
agent.ts
4

Run

The example asks the agent to print:
  • Three TypeScript release changes.
  • Sources for the summary.
  • The actual tool cost, or the reason it could not complete the purchase.
To try another task, edit prompt. Include the spending you allow.

Customize permissions

agentmuxer() exposes all AgentMuxer tools, including purchases. OpenAI tool approval defaults to requireApproval: "never"; AgentMuxer’s spending and payment-confirmation controls still apply. Pass allowedTools to filter exposed tools. For OpenAI approval prompts, pass requireApproval: "always" and implement approval interruptions and resumption. OpenAI receives the application key and connects to AgentMuxer on your behalf. See the SDK reference for all options.

Applications and keys

Manage credentials and spending limits.

Run in production

Handle deployment, failures, and tracing.