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

# OpenRouter

> 자동 Weave 인테그레이션으로 여러 LLM에 OpenRouter의 통합 인터페이스를 사용하세요

이 가이드에서는 OpenRouter를 통해 액세스하는 LLM 호출을 Weave로 자동 트레이스하여, 단일 대시보드에서 애플리케이션의 모델 사용을 모니터링하고 디버그하며 평가하는 방법을 안내합니다.

OpenRouter는 여러 LLM을 위한 통합 인터페이스로, OpenAI GPT-4, Anthropic Claude, Google Gemini 같은 기반 모델과 LLama-3, Mixtral 같은 오픈 소스 모델은 물론 [더 많은 모델](https://openrouter.ai/models)도 지원합니다. 일부 모델은 무료로 제공됩니다.

OpenRouter는 REST API와 [OpenAI SDK 호환](https://openrouter.ai/docs/guides/community/openai-sdk)을 제공하며, Weave는 이를 자동으로 감지해 통합합니다. 자세한 내용은 OpenRouter [빠른 시작 가이드](https://openrouter.ai/docs/quick-start)를 참고하세요. Weave가 OpenAI SDK를 감지하므로 몇 가지 설정만 변경하면 기존 OpenAI 코드를 재사용할 수 있습니다.

OpenAI SDK 코드를 OpenRouter로 전환하려면 [OpenRouter API](https://openrouter.ai/docs/api-keys) 키로 API 키를 바꾸고, `base_url`을 `https://openrouter.ai/api/v1`로 설정한 다음, 모델을 사용 가능한 [채팅 모델](https://openrouter.ai/docs/models) 중 하나로 설정하세요. `weave.init()`를 호출할 때는 트레이스에 사용할 프로젝트 이름을 지정하세요. 지정하지 않으면 Weave가 기본 엔터티를 사용합니다. 기본 엔터티를 찾거나 업데이트하려면 W\&B Models 문서의 [User Settings](https://docs.wandb.ai/platform/app/settings-page/user-settings/#default-team)를 참고하세요. 아래 예시를 실행하면 Weave가 OpenRouter 호출을 Weave 프로젝트의 트레이스로 캡처합니다.

```python lines {5,10-12} theme={null}
import os
import openai
import weave

weave.init('openrouter-weave')

system_content = "You are a travel agent. Be descriptive and helpful."
user_content = "Tell me about San Francisco"

client = openai.OpenAI(
    api_key=os.environ.get("OPENROUTER_API_KEY"),
    base_url="https://openrouter.ai/api/v1",
)
chat_completion = client.chat.completions.create(
    extra_headers={
    "HTTP-Referer": "[YOUR-SITE-URL]", # 선택 사항, openrouter.ai 순위에 앱을 포함하기 위해 사용합니다.
    "X-Title": "[YOUR-APP-NAME]", # 선택 사항. openrouter.ai 순위에 표시됩니다.
    },
    model="meta-llama/llama-3.1-8b-instruct:free",
    messages=[
        {"role": "system", "content": system_content},
        {"role": "user", "content": user_content},
    ],
    temperature=0.7,
    max_tokens=1024,
)
response = chat_completion.choices[0].message.content
print("Model response:\n", response)
```

이 예시는 시작해 보기 위한 기본 예시이지만, 더 복잡한 사용 사례에서 자체 함수와 Weave를 통합하는 방법에 대한 자세한 내용은 [OpenAI](/ko/weave/guides/integrations/openai#track-your-own-ops) 가이드를 참조하세요.
