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

# Anthropic SDK 互換

export const AnthropicCompatibilityModels = () => {
  if (typeof document === "undefined") {
    return null;
  } else {
    let attempts = 0;
    const maxAttempts = 50;
    const INIT_DISPLAY_COUNT = 3;
    const interval = setInterval(() => {
      const clientComponent = document.getElementById("anthropic-compatibility-models");
      if (clientComponent && window.jiekouRemoteData.llmModels.status === 'loaded') {
        const modelList = window.jiekouRemoteData.llmModels.data.filter(model => {
          return (model.endpoints || []).includes('anthropic');
        });
        let displayModels = modelList.slice(0, INIT_DISPLAY_COUNT).map(model => {
          return `<li><span class="model-id-item">${model.id}</span></li>`;
        }).join('');
        let showMoreButton = '';
        if (modelList.length > INIT_DISPLAY_COUNT) {
          showMoreButton = `<button id="show-more-anthropic-compatibility-model-btn" style="margin-left: 32px; color: rgb(40 116 255)">查看更多</button>`;
        }
        clientComponent.innerHTML = `
          <ul>${displayModels}</ul>
          ${showMoreButton}
        `;
        document.getElementById('show-more-anthropic-compatibility-model-btn')?.addEventListener('click', () => {
          clientComponent.innerHTML = `
            <ul>${modelList.map(model => {
            return `<li><span class="model-id-item">${model.id}</span></li>`;
          }).join('')}</ul>
          `;
        });
        clearInterval(interval);
      }
      attempts++;
      if (attempts >= maxAttempts) {
        clearInterval(interval);
      }
    }, 200);
    return <div id="anthropic-compatibility-models"></div>;
  }
};

JieKou AI は Anthropic SDK と互換性のある API サービスを提供しており、既存のアプリケーションに簡単に統合できます。すでに Anthropic SDK を使用してアプリケーションを開発している場合は、base URL と API Key を JieKou AI の API アドレスと API Key に置き換えるだけで利用できます。以下の導入ガイドを参照してください。

## サポートされているモデル

現在、Anthropic SDK 互換性サポートを提供しているのは以下のモデルのみです。

<AnthropicCompatibilityModels />

## クイックスタート

### 1. Anthropic SDK をインストールする

<CodeGroup>
  ```bash Python icon="python" theme={null}
  pip install anthropic
  ```

  ```bash TypeScript icon="js" theme={null}
  npm install @anthropic-ai/sdk
  ```
</CodeGroup>

### 2. クライアントを初期化する

Anthropic SDK は、環境変数 `ANTHROPIC_API_KEY` と `ANTHROPIC_BASE_URL` からそれぞれ API Key と base URL を取得しようとします。クライアントの初期化時にパラメーターで指定することもできます。

* 環境変数による設定

<CodeGroup>
  ```bash Bash icon="terminal" theme={null}
  export ANTHROPIC_BASE_URL="https://api.highwayapi.ai/anthropic"
  export ANTHROPIC_API_KEY="<JieKou AI  API Key>"
  ```
</CodeGroup>

* Anthropic クライアントの初期化時にパラメーターで設定

<CodeGroup>
  ```python Python icon="python" theme={null}
  import anthropic

  client = anthropic.Anthropic(
      base_url="https://api.highwayapi.ai/anthropic",
      api_key="<JieKou AI  API Key>",
      # header を上書き
      default_headers={
          "Content-Type": "application/json",
          "Authorization": "Bearer <JieKou AI  API Key>",
      }
  )
  ```

  ```typescript TypeScript icon="js" theme={null}
  import Anthropic from "@anthropic-ai/sdk";

  const anthropic = new Anthropic({
      baseURL: "https://api.highwayapi.ai/anthropic",
      apiKey: "<JieKou AI  API Key>",
      // header を上書き
      defaultHeaders: {
        "Content-Type": "application/json",
        Authorization: `Bearer <JieKou AI  API Key>`,
      }
  });
  ```
</CodeGroup>

### 3. API を呼び出す

<CodeGroup>
  ```python Python icon="python" theme={null}
  import anthropic

  # クライアントを初期化します。環境変数 `ANTHROPIC_BASE_URL` と `ANTHROPIC_API_KEY` で
  # API Key と base URL を設定済みの場合は、`api_key` と `base_url` パラメーターを省略できます。
  client = anthropic.Anthropic(
      base_url="https://api.highwayapi.ai/anthropic",
      api_key="<JieKou AI  API Key>",
      # header を上書き
      default_headers={
          "Content-Type": "application/json",
          "Authorization": "Bearer <JieKou AI  API Key>",
      }
  )

  message = client.messages.create(
      model="moonshotai/kimi-k2-instruct",
      max_tokens=1000,
      temperature=1,
      system=[
          {
              "type": "text",
              "text": "あなたは JieKou AI の AI アシスタントです。誠実かつ専門的な態度でユーザーを支援し、日本語で質問に回答します。"
          }
      ],
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "text",
                      "text": "あなたは誰ですか？"
                  }
              ]
          }
      ]
  )

  print(message.content)
  ```

  ```typescript TypeScript icon="js" theme={null}
  import Anthropic from "@anthropic-ai/sdk";

  // クライアントを初期化します。環境変数 `ANTHROPIC_BASE_URL` と `ANTHROPIC_API_KEY` で
  // API Key と base URL を設定済みの場合は、`baseURL` と `apiKey` パラメーターを省略できます。
  const anthropic = new Anthropic({
      baseURL: "https://api.highwayapi.ai/anthropic",
      apiKey: "<JieKou AI  API Key>",
      // header を上書き
      defaultHeaders: {
        "Content-Type": "application/json",
        Authorization: `Bearer <JieKou AI  API Key>`,
      },
  });

  const msg = await anthropic.messages.create({
    model: "moonshotai/kimi-k2-instruct",
    max_tokens: 1000,
    temperature: 1,
    system: "あなたは JieKou AI の AI アシスタントです。誠実かつ専門的な態度でユーザーを支援し、日本語で質問に回答します。",
    messages: [
      {
        role: "user",
        content: [
          {
            type: "text",
            text: "あなたは誰ですか？"
          }
        ]
      }
    ]
  });

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