Skip to main content

What is traces?

Traces are a chained collection of workflows and tasks. You can use tree views and waterfalls to better track dependencies and latency.
Traces example

Use agent tracing

1. Get your Keywords AI API key

After you create an account on Keywords AI, you can get your API key from the API keys page.
Create API key placeholder

2. Keywords AI Native (OpenTelemetry)

You just need to add the keywordsai_tracing package to your project and annotate your workflows.
  • Python
  • JS/TS
1

Install the SDK

pip
pip install keywordsai-tracing
2

Set up Environment Variables

Get your API key from the API Keys page in Settings, then configure it in your environment:
.env
KEYWORDSAI_BASE_URL="https://api.keywordsai.co/api"
KEYWORDSAI_API_KEY="YOUR_KEYWORDSAI_API_KEY"
3

A full example with LLM calls

Use the @workflow and @task decorators to instrument your code:
Python
import os
from openai import OpenAI
from keywordsai_tracing.decorators import workflow, task
from keywordsai_tracing.main import KeywordsAITelemetry

# Initialize Keywords AI Telemetry
os.environ["KEYWORDSAI_API_KEY"] = "YOUR_KEYWORDSAI_API_KEY"
k_tl = KeywordsAITelemetry()

# Initialize OpenAI client
client = OpenAI()

@task(name="joke_creation")
def create_joke():
    completion = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Tell me a joke about AI"}],
        temperature=0.7,
        max_tokens=100,
    )
    return completion.choices[0].message.content

@workflow(name="simple_joke_workflow")
def joke_workflow():
    joke = create_joke()
    return joke

if __name__ == "__main__":
    result = joke_workflow()
    print(result)

3. View your traces

You can now see your traces in the Traces.
Traces example

Integrate with your existing AI framework

Keywords AI also integrates seamlessly with popular AI frameworks to give you complete observability into your agent workflows.

OpenAI Agents SDK

Vercel AI SDK

Mastra
I