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

# Compatível com o 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 oferece um serviço de API compatível com o Anthropic SDK, facilitando a integração aos seus aplicativos existentes. Se você já desenvolveu aplicativos usando o Anthropic SDK, basta substituir a base URL e a API Key pelo endereço da API e pela API Key da JieKou AI. Consulte o guia de integração abaixo.

## Modelos compatíveis

No momento, apenas os seguintes modelos oferecem suporte de compatibilidade com o Anthropic SDK:

<AnthropicCompatibilityModels />

## Início rápido

### 1. Instalar o 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. Inicializar o cliente

O Anthropic SDK tentará obter a API Key e a base URL, respectivamente, das variáveis de ambiente `ANTHROPIC_API_KEY` e `ANTHROPIC_BASE_URL`. Você também pode especificá-las por meio de parâmetros ao inicializar o cliente.

* Configuração baseada em variáveis de ambiente

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

* Configuração de parâmetros ao inicializar o cliente 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>",
      # Sobrescrever 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>",
      // Sobrescrever header
      defaultHeaders: {
        "Content-Type": "application/json",
        Authorization: `Bearer <JieKou AI  API Key>`,
      }
  });
  ```
</CodeGroup>

### 3. Chamar a API

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

  # Inicialize o cliente. Se você já tiver configurado a API Key e a base URL
  # por meio das variáveis de ambiente `ANTHROPIC_BASE_URL` e `ANTHROPIC_API_KEY`, pode omitir os parâmetros `api_key` e `base_url`.
  client = anthropic.Anthropic(
      base_url="https://api.highwayapi.ai/anthropic",
      api_key="<JieKou AI  API Key>",
      # Sobrescrever 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": "Você é o assistente de IA da JieKou AI. Você ajudará os usuários com uma atitude honesta e profissional, respondendo às perguntas em chinês."
          }
      ],
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "text",
                      "text": "Quem é você?"
                  }
              ]
          }
      ]
  )

  print(message.content)
  ```

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

  // Inicialize o cliente. Se você já tiver configurado a API Key e a base URL
  // por meio das variáveis de ambiente `ANTHROPIC_BASE_URL` e `ANTHROPIC_API_KEY`, pode omitir os parâmetros `baseURL` e `apiKey`.
  const anthropic = new Anthropic({
      baseURL: "https://api.highwayapi.ai/anthropic",
      apiKey: "<JieKou AI  API Key>",
      // Sobrescrever 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: "Você é o assistente de IA da JieKou AI. Você ajudará os usuários com uma atitude honesta e profissional, respondendo às perguntas em chinês.",
    messages: [
      {
        role: "user",
        content: [
          {
            type: "text",
            text: "Quem é você?"
          }
        ]
      }
    ]
  });

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