Quickstart¶
Get Coalex traces flowing from your AI agent in under 5 minutes.
Prerequisites¶
1. Install the SDK¶
This installs the core SDK plus auto-instrumentation support for all 15 supported LLM frameworks.
Prefer minimal installs?
You can install framework-specific extras instead. See Installation for all options.
2. Set environment variables¶
export COALEX_API_KEY="your-coalex-api-key"
export OPENAI_API_KEY="your-openai-key" # or any other LLM provider
# COALEX_ENDPOINT is optional — defaults to Azure cloud (traces.azure.coalex.ai)
Never hardcode secrets
Always use environment variables or a secrets manager. Never commit API keys to source control.
3. Instrument your agent¶
Create a file called agent.py:
import os
import coalex
from openai import OpenAI
# --- Coalex setup (once at startup) ---
coalex.register(
api_key=os.environ["COALEX_API_KEY"],
service_name="quickstart-agent",
)
coalex.auto_instrument()
# Declare agent (recommended)
coalex.declare_agent(agent_id="quickstart-bot", display_name="Quickstart Bot")
# --- Your agent logic ---
client = OpenAI()
with coalex.coalex_context(agent_id="quickstart-bot", request_id="req-001"):
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is AI governance?"},
],
)
print(response.choices[0].message.content)
Create a file called agent.ts:
import { register, coalexContext, autoInstrument, declareAgent } from "@coalex-ai/sdk";
import OpenAI from "openai";
// --- Coalex setup (once at startup) ---
register({
apiKey: process.env.COALEX_API_KEY!,
serviceName: "quickstart-agent",
});
autoInstrument();
// Declare agent (recommended)
await declareAgent({ agentId: "quickstart-bot", displayName: "Quickstart Bot" });
// --- Your agent logic ---
const client = new OpenAI();
await coalexContext({ agentId: "quickstart-bot", requestId: "req-001" }, async () => {
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is AI governance?" },
],
});
console.log(response.choices[0].message.content);
});
What each call does¶
| Python | TypeScript | Purpose |
|---|---|---|
coalex.register() |
register() |
Configures the OTLP exporter with your endpoint and API key |
coalex.auto_instrument() |
autoInstrument() |
Patches all supported LLM frameworks to emit OpenInference spans |
coalex.declare_agent() |
declareAgent() |
Pre-registers the agent so the dashboard recognizes it immediately |
coalex.coalex_context() |
coalexContext() |
Sets agent_id, request_id, and optional version on all spans within the block |
4. Run it¶
You should see your agent's response printed to the console. Behind the scenes, Coalex has captured the full trace -- including the LLM call, token counts, latency, and model parameters.
5. Verify traces¶
Open your Coalex dashboard and navigate to Traces. You should see a trace for quickstart-agent with:
- The OpenAI chat completion span
- Input and output messages
- Token usage (prompt tokens, completion tokens)
- Latency breakdown
You are all set
Traces are flowing. Every LLM call your agent makes is now automatically captured and sent to Coalex.
Next steps¶
-
Add human-in-the-loop
Use
coalex.evaluate()to assess risk andcoalex.resolve()for human review. -
Manual instrumentation
Use extension decorators like
@retrieval_spanand@tool_spanfor custom spans. -
Key concepts
Understand traces, spans, evaluations, and the Coalex data model.
-
SDK Reference
Full API documentation for every function and decorator.