AI GatewayIntegrations

OpenAI Agents Integration

Integrate CoreValue AI Gateway with OpenAI Agents SDK to build AI agents with tools and full observability.

Introduction

OpenAI Agents SDK is a framework for building AI agents with tool calling, multi-step reasoning, and structured outputs.

How to Integrate

Log into <a href="https://www.corevalue.dev" target="_blank">CoreValue</a> or create an account. Once you have an account, you can generate an <a href="https://www.corevalue.dev/developer" target="_blank">API key here</a>.
COVA_API_KEY=sk-cova-XXXXXXXXXXXXXXXX
npm install @openai/agents openai
# or
pip install openai-agents
import { Agent, setDefaultOpenAIClient } from "@openai/agents";
import OpenAI from "openai";
import dotenv from "dotenv";

dotenv.config();

const client = new OpenAI({
  baseURL: "https://gateway.corevalue.dev/v1",
  apiKey: process.env.COVA_API_KEY
});

// Set the client globally for all agents
setDefaultOpenAIClient(client);
import os
from agents import set_default_openai_client
from openai import OpenAI

client = OpenAI(
    base_url="https://gateway.corevalue.dev/v1",
    api_key=os.getenv("COVA_API_KEY")
)

# Set the client globally for all agents
set_default_openai_client(client)
You can find all supported models at corevalue.dev/models.

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);
from agents import Agent, Runner, tool
from typing import Literal

# Define tools
@tool
def calculator(operation: Literal["add", "subtract", "multiply", "divide"], a: float, b: float) -> float | str:
    """Perform basic arithmetic operations."""
    if operation == "add":
        return a + b
    elif operation == "subtract":
        return a - b
    elif operation == "multiply":
        return a * b
    elif operation == "divide":
        if b == 0:
            return "Error: Division by zero"
        return a / b

# Create an agent with tools
agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    tools=[calculator],
    model="gpt-4o-mini"
)

# Run the agent
result = Runner.run_sync(agent, "Multiply 2 by 2")
print(result.final_output)
All your OpenAI Agents requests are now visible in your CoreValue dashboard.
  • 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!

Request a CoreValue Integration

Looking for a framework or tool not listed here? Request it here!

On this page