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

# Compatibilité avec le SDK Anthropic

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 fournit un service d’API compatible avec le SDK Anthropic afin de faciliter son intégration dans vos applications existantes. Si vous avez déjà développé une application avec le SDK Anthropic, il vous suffit de remplacer la base URL et l’API Key par l’adresse API et l’API Key de JieKou AI. Consultez le guide d’intégration ci-dessous.

## Modèles pris en charge

Actuellement, seuls les modèles suivants prennent en charge la compatibilité avec le SDK Anthropic :

<AnthropicCompatibilityModels />

## Démarrage rapide

### 1. Installer le SDK Anthropic

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

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

### 2. Initialiser le client

Le SDK Anthropic tente de récupérer respectivement l’API Key et la base URL depuis les variables d’environnement `ANTHROPIC_API_KEY` et `ANTHROPIC_BASE_URL`. Vous pouvez également les spécifier via des paramètres lors de l’initialisation du client.

* Configuration via des variables d’environnement

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

* Configuration des paramètres lors de l’initialisation du client 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>",
      # Remplacer les 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>",
      // Remplacer les headers
      defaultHeaders: {
        "Content-Type": "application/json",
        Authorization: `Bearer <JieKou AI  API Key>`,
      }
  });
  ```
</CodeGroup>

### 3. Appeler l’API

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

  # Initialiser le client. Si vous avez déjà défini l’API Key et la base URL
  # via les variables d’environnement `ANTHROPIC_BASE_URL` et `ANTHROPIC_API_KEY`,
  # vous pouvez omettre les paramètres `api_key` et `base_url`.
  client = anthropic.Anthropic(
      base_url="https://api.highwayapi.ai/anthropic",
      api_key="<JieKou AI  API Key>",
      # Remplacer les 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": "Vous êtes l’assistant IA de JieKou AI. Vous aidez les utilisateurs avec honnêteté et professionnalisme, et répondez aux questions en français."
          }
      ],
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "text",
                      "text": "Qui êtes-vous ?"
                  }
              ]
          }
      ]
  )

  print(message.content)
  ```

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

  // Initialiser le client. Si vous avez déjà défini l’API Key et la base URL
  // via les variables d’environnement `ANTHROPIC_BASE_URL` et `ANTHROPIC_API_KEY`,
  // vous pouvez omettre les paramètres `baseURL` et `apiKey`.
  const anthropic = new Anthropic({
      baseURL: "https://api.highwayapi.ai/anthropic",
      apiKey: "<JieKou AI  API Key>",
      // Remplacer les 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: "Vous êtes l’assistant IA de JieKou AI. Vous aidez les utilisateurs avec honnêteté et professionnalisme, et répondez aux questions en français.",
    messages: [
      {
        role: "user",
        content: [
          {
            type: "text",
            text: "Qui êtes-vous ?"
          }
        ]
      }
    ]
  });

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