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

# Anthropic

> Learn how Openlayer integrates with Anthropic

<img width="700" style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/openlayer-44/zlWrng2mbxttdDP9/images/integrations/anthropic_hero.png?fit=max&auto=format&n=zlWrng2mbxttdDP9&q=85&s=04f13cf5cc0f84b26994f671e1ac9705" alt="Anthropic hero" data-path="images/integrations/anthropic_hero.png" />

Openlayer integrates with [Anthropic](https://www.anthropic.com/) in two different ways:

* If you are building an AI system with Anthropic LLMs and want to evaluate it,
  you can use the [SDKs](/api-reference/sdk/overview) to make Openlayer part of your
  workflow.

* Some tests on Openlayer are based on a score produced by an LLM judge. You can
  set any of Anthropic's LLMs as the LLM judge for these tests.

This integration guide explores each of these paths.

## Evaluating Anthropic LLMs

You can set up Openlayer tests to evaluate your Anthropic LLMs
in [monitoring](/monitoring/overview) and [development](/development/overview).

### Monitoring

To use the [monitoring mode](/monitoring/overview), you must instrument your code to publish
the requests your AI system receives to the Openlayer platform. This process
is streamlined for Anthropic LLMs.

To set it up, you must follow the steps in the code snippet below:

```python Python theme={null}
# 1. Set the environment variables
import anthropic
import os

os.environ["ANTHROPIC_API_KEY"] = "YOUR_ANTHROPIC_API_KEY_HERE"
os.environ["OPENLAYER_API_KEY"] = "YOUR_OPENLAYER_API_KEY_HERE"
os.environ["OPENLAYER_INFERENCE_PIPELINE_ID"] = "YOUR_OPENLAYER_INFERENCE_PIPELINE_ID_HERE"

# 2. Call `init` to auto-instrument the installed LLM SDKs (Anthropic, etc.)
from openlayer.lib import init

init()

anthropic_client = anthropic.Anthropic()  # auto-traced by Openlayer

# 3. From now on, every message creation call with
# the `anthropic_client`is traced by Openlayer. E.g.,
completion = anthropic_client.messages.create(
    model="claude-3-opus-20240229",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "How are you doing today?"}
    ],
)
```

<Card title="See full Python example" icon="python" iconType="duotone" href="https://colab.research.google.com/github/openlayer-ai/openlayer-python/blob/main/examples/tracing/anthropic/anthropic_tracing.ipynb" />

Once the code is instrumented, all your Anthropic LLM calls are automatically published to Openlayer,
along with metadata, such as latency, number of tokens, cost estimate, and more.

If you navigate to the "Data" page of your Openlayer data source, you can see
the traces for each request.

<img width="700" style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/openlayer-44/zlWrng2mbxttdDP9/images/integrations/anthropic_trace.png?fit=max&auto=format&n=zlWrng2mbxttdDP9&q=85&s=0b1c6aa80176c16dcb7e769f9d0038b0" alt="Anthropic trace" data-path="images/integrations/anthropic_trace.png" />

<Note>
  If the Anthropic LLM call is just one of the steps of your AI system, you can
  use the code snippets above together with [tracing](/monitoring/tracing). In
  this case, your Anthropic LLM calls get added as a step of a larger trace.
  Refer to the [Tracing guide](/monitoring/tracing) for details.
</Note>

After your AI system requests are continuously published and logged by Openlayer, you can
[create tests](/tests/overview) that run at a regular cadence on top of them.

Refer to the [Monitoring overview](/monitoring/overview), for details on Openlayer's
monitoring mode, to the [Publishing data guide](/monitoring/publishing-data), for more
information on setting it up, or to the [Tracing guide](/monitoring/tracing), to
understand how to trace more complex systems.

### Development

In [development mode](/development/overview), Openlayer becomes a step in
your CI/CD pipeline, and your tests get automatically evaluated after being triggered
by some events.

Openlayer tests often rely on your AI system's outputs on a validation
dataset. As discussed in the
[Configuring output generation guide](/development/configuring-output-generation),
you have two options:

1. either provide a way for Openlayer to run your AI system on your datasets, or
2. before pushing, generate the model outputs yourself and push them alongside your
   artifacts.

For AI systems built with Anthropic LLMs, if you are **not** computing
your system's outputs yourself, you must provide your **API credentials**.

To do so, go to **Settings** → **Environment** and add the `ANTHROPIC_API_KEY`
secret.

If you don't add the required Anthropic API key, you'll encounter a "Missing API key"
error when Openlayer tries to run your AI system to get its outputs.

## Using Anthropic LLMs as the LLM judge

Some tests on Openlayer rely on scores produced by an LLM judge. For example,
tests that use [Ragas metrics](/integrations/ragas)
and the custom [LLM evaluator test](/tests/catalog/l-l-m-rubric-threshold).

You can use any of Anthropic's LLMs as the underlying LLM evaluator for these tests.

First, add `ANTHROPIC_API_KEY` under **Settings** → **Environment** at the workspace or
project level. Provider keys are not entered on the LLM-as-a-judge page.

Open your project and go to **Settings** → **LLM-as-a-judge**. Under **Default
LLM**, choose **Anthropic**, type a Claude model name, and select **Select**.

<img width="700" style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/openlayer-44/Xmv1c-JcPP5JuT3M/images/integrations/llm_as_a_judge_menu.png?fit=max&auto=format&n=Xmv1c-JcPP5JuT3M&q=85&s=0e1a342f0dcf8d58a8a4120a98752d53" alt="Default LLM provider menu open with Anthropic visible" data-path="images/integrations/llm_as_a_judge_menu.png" />

You can also add **Custom judge instructions** and configure **Sampling settings**
on this page.

<img width="700" style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/openlayer-44/Xmv1c-JcPP5JuT3M/images/integrations/llm_as_a_judge_sampling.png?fit=max&auto=format&n=Xmv1c-JcPP5JuT3M&q=85&s=0315013827ea5915700001a897719828" alt="Sampling settings for LLM-based metrics" data-path="images/integrations/llm_as_a_judge_sampling.png" />
