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

# Quickstart

> Get started with RDK in 5 minutes

## Installation

Install RDK using pip or uv:

<CodeGroup>
  ```bash pip theme={null}
  pip install rdk --extra-index-url https://pypi.fury.io/021labs/
  ```

  ```bash uv theme={null}
  uv add rdk --extra-index-url https://pypi.fury.io/021labs/
  ```
</CodeGroup>

## Basic Setup

### 1. Set your API key

```bash theme={null}
export RDK_API_KEY="your-api-key"
```

### 2. Initialize and trace

Call `init()` to start tracing — all LLM calls are captured automatically:

<CodeGroup>
  ```python Anthropic theme={null}
  from rdk import init, shutdown
  from anthropic import Anthropic

  init()

  client = Anthropic()
  response = client.messages.create(
      model="claude-sonnet-4-6",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Hello!"}]
  )

  shutdown()
  ```

  ```python OpenAI theme={null}
  from rdk import init, shutdown
  from openai import OpenAI

  init()

  client = OpenAI()
  response = client.chat.completions.create(
      model="gpt-4o",
      messages=[{"role": "user", "content": "Hello!"}]
  )

  shutdown()
  ```

  ```python Gemini theme={null}
  from rdk import init, shutdown
  import google.generativeai as genai

  init()

  model = genai.GenerativeModel("gemini-1.5-pro")
  response = model.generate_content("Hello!")

  shutdown()
  ```
</CodeGroup>

Use `@observe` to group multiple calls into a single trace:

<CodeGroup>
  ```python Anthropic theme={null}
  from rdk import observe
  from anthropic import Anthropic

  @observe(name="chat-completion")
  def chat(message: str) -> str:
      client = Anthropic()
      response = client.messages.create(
          model="claude-sonnet-4-6",
          max_tokens=1024,
          messages=[{"role": "user", "content": message}]
      )
      return response.content[0].text
  ```

  ```python OpenAI theme={null}
  from rdk import observe
  from openai import OpenAI

  @observe(name="chat-completion")
  def chat(message: str) -> str:
      client = OpenAI()
      response = client.chat.completions.create(
          model="gpt-4o",
          messages=[{"role": "user", "content": message}]
      )
      return response.choices[0].message.content
  ```

  ```python Gemini theme={null}
  from rdk import observe
  import google.generativeai as genai

  @observe(name="chat-completion")
  def chat(message: str) -> str:
      model = genai.GenerativeModel("gemini-1.5-pro")
      response = model.generate_content(message)
      return response.text
  ```
</CodeGroup>

### 3. Shutdown gracefully

Flush remaining traces before your app exits:

```python theme={null}
from rdk import shutdown

shutdown()
```

## Complete Example

```python theme={null}
from rdk import observe, shutdown
from anthropic import Anthropic

@observe(name="summarize")
def summarize(text: str) -> str:
    client = Anthropic()
    response = client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=500,
        messages=[{"role": "user", "content": f"Summarize this text:\n\n{text}"}]
    )
    return response.content[0].text

result = summarize("Your long text here...")
print(result)

shutdown()
```

## Custom Configuration

Need custom settings? Call `init()` before your first `@observe` call:

```python theme={null}
from rdk import init

init(
    sample_rate=0.1,  # Capture 10% of traces
    redact_pii=True,  # Remove emails, phones, SSNs, etc.
)
```

## Configuration Options

| Parameter              | Type     | Default                        | Description                                        |
| ---------------------- | -------- | ------------------------------ | -------------------------------------------------- |
| `api_key`              | str      | `RDK_API_KEY` env var          | Your RDK API key                                   |
| `endpoint`             | str      | `https://collector.021labs.ai` | Collector URL                                      |
| `batch_size`           | int      | 10                             | Number of spans per batch                          |
| `flush_interval`       | float    | 5.0                            | Seconds between auto-flushes                       |
| `timeout`              | float    | 30.0                           | HTTP request timeout in seconds                    |
| `sample_rate`          | float    | 1.0                            | Fraction of traces to capture (0–1)                |
| `redact_pii`           | bool     | False                          | Enable built-in PII redaction                      |
| `redactor`             | Callable | None                           | Custom redaction function                          |
| `debug`                | bool     | False                          | Enable verbose debug logging                       |
| `enabled`              | bool     | True                           | Set to `False` to disable all tracing              |
| `mode`                 | str      | `"default"`                    | Operating mode: `"default"`, `"test"`, or `"eval"` |
| `on_error`             | Callable | None                           | Callback for transport errors                      |
| `instrument_langchain` | bool     | True                           | Auto-instrument LangChain                          |
| `instrument_anthropic` | bool     | True                           | Auto-instrument Anthropic SDK                      |
| `instrument_openai`    | bool     | True                           | Auto-instrument OpenAI SDK                         |
| `instrument_gemini`    | bool     | True                           | Auto-instrument Gemini SDK                         |

See [init()](/api-reference/init) for full documentation.

## Environment Variables

| Variable       | Effect                                     |
| -------------- | ------------------------------------------ |
| `RDK_API_KEY`  | API key for authentication                 |
| `RDK_ENDPOINT` | Override the default collector URL         |
| `RDK_MODE`     | Operating mode (`default`, `test`, `eval`) |

## What Gets Traced?

RDK automatically captures all LLM calls:

* **Token Usage** — Prompt, completion, and total tokens
* **Cost** — Calculated automatically based on model pricing
* **Timing** — Start time, end time, and duration
* **Model Info** — Model name and provider
* **Errors** — Exception messages

Input messages and output content are **not** captured by default. Enable them with `capture_input=True` and `capture_output=True` on `@observe`.

## Next Steps

<CardGroup cols={2}>
  <Card title="Anthropic Integration" icon="brain" href="/integrations/anthropic">
    Set up Claude tracing
  </Card>

  <Card title="PII Redaction" icon="shield" href="/features/pii-redaction">
    Protect sensitive data
  </Card>

  <Card title="Testing" icon="flask" href="/guides/testing">
    Write tests without real API calls
  </Card>

  <Card title="Synthetic Worlds" icon="flask-vial" href="/guides/synthetic-worlds">
    Simulate tool calls for fast iteration
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/init">
    Full parameter reference
  </Card>
</CardGroup>
