> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getnetra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Replicate

> Trace Replicate AI model calls with Netra auto-instrumentation. Monitor cloud-hosted model inference, predictions, and latency automatically.

<img src="https://mintcdn.com/netra/IXT7TOAHn4HQhvyF/images/integration-logos/llm-providers/replicate.png?fit=max&auto=format&n=IXT7TOAHn4HQhvyF&q=85&s=a45fe35cc585d2c612757db26ca389f1" alt="Replicate" width="383" height="80" data-path="images/integration-logos/llm-providers/replicate.png" />

## Installation

Install both the Netra SDK and Replicate SDK:

<CodeGroup>
  ```bash Python theme={null}
  pip install netra-sdk replicate
  ```

  ```bash Typescript theme={null}
  npm install netra-sdk replicate
  ```
</CodeGroup>

## Usage

Initialize the Netra SDK with Replicate instrumentation enabled. The SDK automatically traces all Replicate API calls once initialized.

<CodeGroup>
  ```python Python theme={null}
  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)
  ```

  ```typescript Typescript theme={null}
  import { Netra } from "netra-sdk";
  import Replicate from "replicate";

  async function main() {
    // Initialize Netra with Replicate instrumentation (must await)
    await Netra.init({
      appName: "my-ai-app",
      headers: `x-api-key=${process.env.NETRA_API_KEY}`,
      traceContent: true
    });

    // Use Replicate client as usual - all calls are automatically traced
    const replicate = new Replicate({
      auth: process.env.REPLICATE_API_TOKEN
    });

    const output = await replicate.run(
      "meta/llama-2-70b-chat:latest",
      {
        input: {
          prompt: "What is observability?"
        }
      }
    );

    console.log(output);
  }

  main();
  ```
</CodeGroup>

### Streaming Responses

The SDK automatically handles streaming responses and captures the complete output:

<CodeGroup>
  ```python Python theme={null}
  for event in replicate.stream(
      "meta/llama-2-70b-chat:latest",
      input={"prompt": "Tell me a story"}
  ):
      print(event, end="")
  ```

  ```typescript Typescript theme={null}
  for await (const event of replicate.stream(
    "meta/llama-2-70b-chat:latest",
    {
      input: {
        prompt: "Tell me a story"
      }
    }
  )) {
    process.stdout.write(event.toString());
  }
  ```
</CodeGroup>

### Image Generation

Image generation models are also automatically instrumented:

<CodeGroup>
  ```python Python theme={null}
  output = replicate.run(
      "stability-ai/sdxl:latest",
      input={"prompt": "A futuristic cityscape at sunset"}
  )

  print(output)
  ```

  ```typescript Typescript theme={null}
  const output = await replicate.run(
    "stability-ai/sdxl:latest",
    {
      input: {
        prompt: "A futuristic cityscape at sunset"
      }
    }
  );

  console.log(output);
  ```
</CodeGroup>

### Selective Instrumentation

Control which integrations are enabled using the `instruments` or `blockInstruments` configuration:

<CodeGroup>
  ```python Python theme={null}
  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}
  )
  ```

  ```typescript Typescript theme={null}
  import { Netra, NetraInstruments } from "netra-sdk";

  // Only enable Replicate instrumentation
  await Netra.init({
    headers: `x-api-key=${process.env.NETRA_API_KEY}`,
    instruments: new Set([NetraInstruments.REPLICATE])
  });

  // Or block specific instrumentations
  await Netra.init({
    headers: `x-api-key=${process.env.NETRA_API_KEY}`,
    blockInstruments: new Set([NetraInstruments.HTTP])
  });
  ```
</CodeGroup>

## Next Steps

* [Quick Start Guide](https://docs.getnetra.ai/quick-start/python) - Complete setup and configuration
* [Auto Instrumentation](https://docs.getnetra.ai/tracing/auto-instrumentation) - Automatic tracing for supported libraries
* [Decorators](https://docs.getnetra.ai/tracing/decorators) - Add custom tracing with `@workflow`, `@agent`, and `@task` decorators
* [Session Tracking](https://docs.getnetra.ai/tracing/session) - Track user sessions and conversations
* [Replicate Documentation](https://replicate.com/docs/get-started/nodejs) - Official Replicate quickstart guide
