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

# Anthropic

> CoreWeave Forge SDK를 사용해 Agent Lens에서 Anthropic SDK Call을 트레이스하세요.

CoreWeave Forge SDK는 Python 및 Node.js용 Anthropic SDK로 수행하는 Call을 자동으로 트레이스합니다. 트레이싱을 초기화하면 대화 안에서 수행하는 각 Call이 LLM span으로 Agent Lens에 기록되며, 여기에는 메시지, 도구 Call, 미디어, 요청 설정, 토큰 사용량, 프롬프트 캐시 사용량이 함께 포함됩니다. Anthropic SDK를 호출하는 방식은 바꿀 필요가 없습니다.

이 인테그레이션은 스트리밍, Messages 스트림 헬퍼, 구조화된 출력 파싱을 포함한 Messages API를 트레이스합니다. TypeScript에서는 Message Batches API 호출도 도구 오퍼레이션으로 트레이스합니다.

<h2 id="prerequisites">
  사전 요구 사항
</h2>

* CoreWeave Forge 계정 및 `WANDB_API_KEY` 환경 변수로 설정한 [API 키](https://forge.coreweave.com/settings#apikeys)
* `ANTHROPIC_API_KEY` 환경 변수로 설정한 [Anthropic API 키](https://console.anthropic.com/settings/keys)
* Python: Python 3.10 이상 및 `anthropic` 0.18.0 이상
* TypeScript: Node.js 18.19 이상(또는 20.6 이상) 및 `@anthropic-ai/sdk` 0.52.0 이상

<h2 id="install-packages">
  패키지 설치
</h2>

<CodeGroup>
  ```bash Python theme={"system"}
  pip install "coreweave[anthropic]"
  ```

  ```bash TypeScript theme={"system"}
  npm install @coreweave/forge-sdk @anthropic-ai/sdk
  ```
</CodeGroup>

<h2 id="trace-anthropic-conversations">
  Anthropic 대화 트레이싱
</h2>

Forge 팀 이름과 프로젝트 이름을 지정해 `tracing.init()`을 호출하세요. Python에서는 Anthropic SDK를 호출 전에 임포트하든 후에 임포트하든 `tracing.init()`이 SDK를 패치합니다. TypeScript에서는 TypeScript 탭에 나와 있는 계측 플래그를 사용해 Node를 시작하세요.

Agent Lens에는 대화 안에서 실행된 Call만 표시됩니다. 대화 밖에서 실행된 Call에는 대화 ID가 없으므로 Agent Lens에 나타나지 않습니다. 에이전트 세션마다 대화를 하나씩 생성하고, 사용자 메시지마다 턴을 시작하세요. 모든 턴이 대화 ID를 공유하므로 Agent Lens는 이 턴들을 하나의 대화로 묶어 표시하며, 각 Call은 자신이 실행된 턴의 LLM span이 됩니다.

<Tabs>
  <Tab title="Python">
    ```python lines theme={"system"}
    from anthropic import Anthropic
    from coreweave.forge.agentlens import tracing

    tracing.init("[YOUR-TEAM]/[YOUR-PROJECT]")
    client = Anthropic()

    questions = [
        "What is inference latency?",
        "How does batching affect it?",
        "Summarize what we discussed in one sentence.",
    ]

    history = []
    with tracing.Conversation(agent_name="support-agent") as conversation:
        for question in questions:
            with conversation.start_turn(user_message=question):
                history.append({"role": "user", "content": question})
                response = client.messages.create(
                    model="claude-sonnet-5",
                    max_tokens=256,
                    messages=history,
                )
                answer = response.content[0].text
                history.append({"role": "assistant", "content": answer})
                print(answer)

    tracing.shutdown()
    ```
  </Tab>

  <Tab title="TypeScript">
    각 에이전트 run을 `tracing.runIsolated()`로 감싸 해당 대화와 턴이 동시에 실행되는 다른 run과 섞이지 않도록 하세요.

    ```typescript lines title="app.mjs" theme={"system"}
    import Anthropic from '@anthropic-ai/sdk';
    import {tracing} from '@coreweave/forge-sdk/agentlens';

    await tracing.init('[YOUR-TEAM]/[YOUR-PROJECT]');
    const anthropic = new Anthropic();

    const questions = [
      'What is inference latency?',
      'How does batching affect it?',
      'Summarize what we discussed in one sentence.',
    ];

    await tracing.runIsolated(async () => {
      const conversation = tracing.startConversation({agentName: 'support-agent'});
      const history = [];
      try {
        for (const question of questions) {
          const turn = conversation.startTurn({userMessage: question});
          try {
            history.push({role: 'user', content: question});
            const response = await anthropic.messages.create({
              model: 'claude-sonnet-5',
              max_tokens: 256,
              messages: history,
            });
            const answer = response.content[0].text;
            history.push({role: 'assistant', content: answer});
            console.log(answer);
          } finally {
            turn.end();
          }
        }
      } finally {
        conversation.end();
      }
    });

    await tracing.shutdown();
    ```

    계측 플래그를 지정해 스크립트를 실행하세요. 이 플래그는 코드보다 먼저 Forge 계측을 로드하므로, 코드에서 Anthropic SDK를 임포트하는 시점에 SDK가 패치됩니다.

    ```bash theme={"system"}
    node --import=@coreweave/forge-sdk/instrument app.mjs
    ```

    번들러가 의존성을 하나의 파일로 합치는 경우처럼 플래그를 사용할 수 없다면, 대신 클라이언트를 래핑하세요.

    ```typescript theme={"system"}
    import {integrations} from '@coreweave/forge-sdk/agentlens';

    const anthropic = integrations.wrapAnthropic(new Anthropic());
    ```

    플래그 없이 실행하면 `tracing.init()`이 이에 대한 경고를 한 번 출력합니다. 클라이언트를 래핑했다면 이 경고는 무시해도 됩니다.
  </Tab>
</Tabs>

요청마다 턴을 하나씩 처리하는 웹 앱처럼 나중에 기존 대화에 턴을 추가해야 한다면, 대화를 생성할 때마다 같은 `conversation_id`(Python) 또는 `conversationId`(TypeScript)를 전달하세요.

대화, 턴 및 기타 span 유형에 대한 자세한 내용은 [에이전트 트레이싱](/ko/products/agent-lens/tracing/instrument)을 참조하세요.

<h2 id="turn-off-automatic-patching">
  자동 패치 끄기
</h2>

Python에서는 `tracing.init()`에 `autopatch_integrations=False`를 전달하세요. 그러면 `tracing.integrations.patch_anthropic()` 및 `tracing.integrations.unpatch_anthropic()`으로 Anthropic SDK를 직접 패치하거나 패치를 해제할 수 있습니다.

TypeScript에서는 `--import=@coreweave/forge-sdk/instrument` 플래그 없이 실행한 다음, 트레이스하려는 클라이언트만 `integrations.wrapAnthropic()`으로 래핑하세요.

<h2 id="view-your-traces">
  트레이스 보기
</h2>

[CoreWeave Forge](https://forge.coreweave.com)의 제품 메뉴에서 Agent Lens를 선택하고, 사이드 메뉴 상단의 프로젝트 선택기에서 프로젝트를 선택한 다음 **Conversations**를 선택하세요. 자세한 내용은 [에이전트 활동 보기](/ko/products/agent-lens/conversations/view-activity)를 참조하세요.
