Skip to main content

Introduction

OpenAI Agents SDK is a framework for building AI agents with tool calling, multi-step reasoning, and structured outputs.
1
HELICONE_API_KEY=sk-helicone-...
2
npm install @openai/agents openai
# or
pip install openai-agents
3

Configure OpenAI Agents with Helicone AI Gateway

import { Agent, setDefaultOpenAIClient } from "@openai/agents";
import OpenAI from "openai";
import dotenv from "dotenv";

dotenv.config();

const client = new OpenAI({
  baseURL: "https://ai-gateway.helicone.ai/v1",
  apiKey: process.env.HELICONE_API_KEY
});

// Set the client globally for all agents
setDefaultOpenAIClient(client);
4

Use OpenAI Agents normally

Your existing OpenAI Agents code continues to work without any changes:
import { Agent, run, tool } from "@openai/agents";
import { z } from "zod";

// Define tools
const calculator = tool({
  name: "calculator",
  description: "Perform basic arithmetic operations",
  parameters: z.object({
    operation: z.enum(["add", "subtract", "multiply", "divide"]),
    a: z.number(),
    b: z.number()
  }),
  async execute({ operation, a, b }) {
    switch (operation) {
      case "add":
        return a + b;
      case "subtract":
        return a - b;
      case "multiply":
        return a * b;
      case "divide":
        if (b === 0) return "Error: Division by zero";
        return a / b;
    }
  }
});

// Create an agent with tools
const agent = new Agent({
  name: "Assistant",
  instructions: "You are a helpful assistant.",
  tools: [calculator],
  model: "gpt-4o-mini",
});

// Run the agent
const result = await run(agent, "Multiply 2 by 2");
console.log(result.finalOutput);
5
  • Request/response bodies
  • Latency metrics
  • Token usage and costs
  • Model performance analytics
  • Tool usage tracking
  • Agent reasoning steps
  • Error tracking
  • Session tracking
While you’re here, why not give us a star on GitHub? It helps us a lot!
Looking for a framework or tool not listed here? Request it here!

AI Gateway Overview

Learn about Helicone’s AI Gateway features and capabilities

Provider Routing

Configure intelligent routing and automatic failover

Model Registry

Browse all available models and providers

Prompt Management

Version and manage prompts with Helicone Prompts

Custom Properties

Add metadata to track and filter your requests

Sessions

Track multi-turn conversations and user sessions

Rate Limiting

Configure rate limits for your applications

Tool Usage Tracking

Monitor tool calls and function usage in your agents