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
COVA_API_KEY=sk-cova-XXXXXXXXXXXXXXXXnpm install @openai/agents openai
# or
pip install openai-agentsimport { 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)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)- 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!
Related Documentation
AI Gateway Overview
Learn about CoreValue'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 CoreValue 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