> ## 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.

# Compatible with 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 provides an Anthropic SDK-compatible API service, making it easy to integrate into your existing applications. If you have already developed an application using the Anthropic SDK, you only need to replace the base URL and API Key with the JieKou AI API address and API Key. Please refer to the integration guide below.

## Supported Models

Currently, only the following models support Anthropic SDK compatibility:

<AnthropicCompatibilityModels />

## Quick Start

### 1. Install the 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. Initialize the Client

The Anthropic SDK will try to retrieve the API Key and base URL from the environment variables `ANTHROPIC_API_KEY` and `ANTHROPIC_BASE_URL`, respectively. You can also specify them through parameters when initializing the client.

* Set via environment variables

<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>

* Set parameters when initializing the Anthropic client

<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>",
      # Override headers
      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>",
      // Override headers
      defaultHeaders: {
        "Content-Type": "application/json",
        Authorization: `Bearer <JieKou AI  API Key>`,
      }
  });
  ```
</CodeGroup>

### 3. Call the API

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

  # Initialize the client. If you have already set the API Key and base URL
  # through the environment variables `ANTHROPIC_BASE_URL` and `ANTHROPIC_API_KEY`,
  # you can omit the `api_key` and `base_url` parameters.
  client = anthropic.Anthropic(
      base_url="https://api.highwayapi.ai/anthropic",
      api_key="<JieKou AI  API Key>",
      # Override headers
      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": "You are the JieKou AI AI assistant. You help users with an honest and professional attitude, and answer questions in English."
          }
      ],
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "text",
                      "text": "Who are you?"
                  }
              ]
          }
      ]
  )

  print(message.content)
  ```

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

  // Initialize the client. If you have already set the API Key and base URL
  // through the environment variables `ANTHROPIC_BASE_URL` and `ANTHROPIC_API_KEY`,
  // you can omit the `baseURL` and `apiKey` parameters.
  const anthropic = new Anthropic({
      baseURL: "https://api.highwayapi.ai/anthropic",
      apiKey: "<JieKou AI  API Key>",
      // Override headers
      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: "You are the JieKou AI AI assistant. You help users with an honest and professional attitude, and answer questions in English.",
    messages: [
      {
        role: "user",
        content: [
          {
            type: "text",
            text: "Who are you?"
          }
        ]
      }
    ]
  });

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