OpenAI is a leading provider of AI tools and services. Explore the OpenAI API for more information.

1

Install the AgentOps SDK

pip install agentops
2

Install the OpenAI SDK

openai<1.0.0 has limited support while openai>=1.0.0 is continuously supported.

pip install openai

To install openai<1.0.0, use the following:

pip install "openai<1.0.0"
3

Add 3 lines of code

Make sure to call agentops.init before calling any openai, cohere, crew, etc models.

import agentops
from openai import OpenAI

agentops.init(<INSERT YOUR API KEY HERE>)
client = OpenAI()
...
# End of program (e.g. main.py)
agentops.end_session("Success")

Set your API key as an .env variable for easy access.

AGENTOPS_API_KEY=<YOUR API KEY>
OPENAI_API_KEY=<YOUR OPENAI API KEY>

Read more about environment variables in Advanced Configuration

4

Run your Agent

Execute your program and visit app.agentops.ai/drilldown to observe your Agent! 🕵️

After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard

Clickable link to session

Full Examples

from openai import OpenAI
import agentops

agentops.init(<INSERT YOUR API KEY HERE>)
client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{
        "role": "user",
        "content": "Write a haiku about AI and humans working together"
    }]
)

print(response.choices[0].message.content)
agentops.end_session('Success')

Streaming examples

from openai import OpenAI
import agentops

agentops.init(<INSERT YOUR API KEY HERE>)
client = OpenAI()

stream = client.chat.completions.create(
    model="gpt-4o-mini",
    stream=True,
    messages=[{
          "role": "user",
          "content": "Write a haiku about AI and humans working together"
    }],
)

for chunk in stream:
  print(chunk.choices[0].delta.content or "", end="")

agentops.end_session('Success')