Anthropic tracing with Future AGI
Trace Anthropic Messages API calls in Future AGI with the Python or TypeScript traceAI instrumentor.
Trace Anthropic Messages API calls in Future AGI, including request timing, model details and captured messages.
1. Install
pip install traceAI-anthropic anthropicnpm install @traceai/anthropic@0.1.3 '@anthropic-ai/sdk@^0.27.3' @traceai/fi-core @opentelemetry/instrumentation The TypeScript instrumentor declares @anthropic-ai/sdk ^0.27.3 as its peer dependency. Keep that SDK range rather than installing the latest major version.
2. Set environment variables
Export credentials before running either example. Set ANTHROPIC_MODEL to a Messages API model available to your account.
export FI_API_KEY="YOUR_FI_API_KEY"
export FI_SECRET_KEY="YOUR_FI_SECRET_KEY"
export ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"
export ANTHROPIC_MODEL="YOUR_MODEL_ID"
Messages, responses, images and tool payloads can be captured by default. To hide input and output content, set these TraceConfig controls before initialization:
export FI_HIDE_INPUTS=true FI_HIDE_OUTPUTS=true
export FI_HIDE_INPUT_MESSAGES=true FI_HIDE_OUTPUT_MESSAGES=true
Model metadata and custom attributes can still be exported. Error text may contain request data, credentials or local paths; input/output hiding alone is not a guarantee that every error or custom field is redacted. Review the controls supported by your installed core version before tracing sensitive workloads.
3. Initialize tracing
Use the same project name for the provider and the project you open in Observe.
from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
trace_provider = register(
project_type=ProjectType.OBSERVE,
project_name="anthropic_project",
)import { register, ProjectType } from "@traceai/fi-core";
const tracerProvider = register({
projectType: ProjectType.OBSERVE,
projectName: "anthropic_project",
}); 4. Instrument the client
Instrument before making API calls. The TypeScript example patches the imported SDK explicitly so it does not depend on module-loading order.
from traceai_anthropic import AnthropicInstrumentor
AnthropicInstrumentor().instrument(tracer_provider=trace_provider)import Anthropic from "@anthropic-ai/sdk";
import { AnthropicInstrumentation } from "@traceai/anthropic";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
const instrumentation = new AnthropicInstrumentation();
registerInstrumentations({
instrumentations: [instrumentation],
tracerProvider,
});
instrumentation.manuallyInstrument(Anthropic); 5. Make a request
Run these snippets in the same file as the setup above. Shutdown flushes pending spans before this short script exits.
import os
import anthropic
client = anthropic.Anthropic()
try:
message = client.messages.create(
model=os.environ["ANTHROPIC_MODEL"],
max_tokens=128,
messages=[{"role": "user", "content": "Explain what an API is in one sentence."}],
)
print(message.content)
finally:
trace_provider.shutdown()const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const model = process.env.ANTHROPIC_MODEL;
if (!model) throw new Error("Set ANTHROPIC_MODEL");
try {
const message = await client.messages.create({
model,
max_tokens: 128,
messages: [{ role: "user", content: "Explain what an API is in one sentence." }],
});
console.log(message.content);
} finally {
await tracerProvider.shutdown();
} View the trace
In Future AGI, open Observe, select anthropic_project, and open the trace to inspect the model call. Message content depends on the capture controls you configured.
Questions & Discussion