Anthropic

Integrate Anthropic Claude with Future AGI for auto-instrumented tracing. Install traceAI-anthropic and capture LLM calls with full observability.

1. Installation

First install the traceAI and Anthropic packages.

pip install traceAI-anthropic anthropic
npm install @traceai/anthropic @anthropic-ai/sdk

2. Set Environment Variables

Set up your environment variables to authenticate with both FutureAGI and Anthropic.

import os

os.environ["FI_API_KEY"] = FI_API_KEY
os.environ["FI_SECRET_KEY"] = FI_SECRET_KEY
os.environ["ANTHROPIC_API_KEY"] = ANTHROPIC_API_KEY
process.env.FI_API_KEY = FI_API_KEY;
process.env.FI_SECRET_KEY = FI_SECRET_KEY;
process.env.ANTHROPIC_API_KEY = ANTHROPIC_API_KEY;

3. Initialize Trace Provider

Set up the trace provider to create a new project in FutureAGI, establish telemetry data pipelines .

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 traceProvider = register({
    project_type: ProjectType.OBSERVE,
    project_name: "anthropic_project",
});

4. Instrument your Project

Instrument your Project with Anthropic Instrumentor. This step ensures that all interactions with the Anthropic are tracked and monitored.

from traceai_anthropic import AnthropicInstrumentor

AnthropicInstrumentor().instrument(tracer_provider=trace_provider)
import { AnthropicInstrumentation } from "@traceai/anthropic";
import { registerInstrumentations } from "@opentelemetry/instrumentation";

 const anthropicInstrumentation = new AnthropicInstrumentation({});

  registerInstrumentations({
    instrumentations: [anthropicInstrumentation],
    tracerProvider: tracerProvider,
  });

5. Interact with Anthropic

Interact with the Anthropic as you normally would. Our Instrumentor will automatically trace and send the telemetry data to our platform.

import anthropic
import httpx
import base64

image_url = "https://upload.wikimedia.org/wikipedia/commons/a/a7/Camponotus_flavomarginatus_ant.jpg"
image_media_type = "image/jpeg"
image_data = base64.standard_b64encode(httpx.get(image_url).content).decode("utf-8")

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-3-7-sonnet-20250219",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "source": {
                        "type": "base64",
                        "media_type": image_media_type,
                        "data": image_data,
                    },
                },
                {
                    "type": "text",
                    "text": "Describe this image."
                }
            ],
        }
    ],
)

print(message)
import { Anthropic } from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

const message = await client.messages.create({
      model: "claude-3-7-sonnet-20250219",
      max_tokens: 50,
      messages: [{ role: "user", content: "Hello Claude! Write a short haiku." }],
    });
Was this page helpful?

Questions & Discussion