Skip to main content

Installation

Install both the Netra SDK and Replicate SDK:
pip install netra-sdk replicate

Usage

Initialize the Netra SDK with Replicate instrumentation enabled. The SDK automatically traces all Replicate API calls once initialized.
from netra import Netra
import replicate
import os

# Initialize Netra with Replicate instrumentation
Netra.init(
    app_name="my-ai-app",
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    trace_content=True
)

# Use Replicate client as usual - all calls are automatically traced
output = replicate.run(
    "meta/llama-2-70b-chat:latest",
    input={"prompt": "What is observability?"}
)

print(output)

Streaming Responses

The SDK automatically handles streaming responses and captures the complete output:
for event in replicate.stream(
    "meta/llama-2-70b-chat:latest",
    input={"prompt": "Tell me a story"}
):
    print(event, end="")

Image Generation

Image generation models are also automatically instrumented:
output = replicate.run(
    "stability-ai/sdxl:latest",
    input={"prompt": "A futuristic cityscape at sunset"}
)

print(output)

Selective Instrumentation

Control which integrations are enabled using the instruments or blockInstruments configuration:
from netra import Netra
from netra.instrumentation.instruments import InstrumentSet

# Only enable Replicate instrumentation
Netra.init(
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    instruments={InstrumentSet.REPLICATE}
)

# Or block specific instrumentations
Netra.init(
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    block_instruments={InstrumentSet.HTTPX}
)

Next Steps

Last modified on February 3, 2026