> ## Documentation Index
> Fetch the complete documentation index at: https://novita.ai/docs/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.novitaRemoteData.llmModels.status === 'loaded') {
        const modelList = window.novitaRemoteData.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)">View More</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>;
  }
};

Novita AI fournit une API de compatibilité qui vous permet d’utiliser le SDK Anthropic avec les modèles Novita AI. C’est utile si vous utilisez déjà le SDK Anthropic et souhaitez passer aux modèles Novita AI.

## Modèles pris en charge

Actuellement, seuls les modèles suivants sont compatibles avec le SDK Anthropic :

<AnthropicCompatibilityModels />

## Guide de démarrage rapide

Ce guide montre comment utiliser le SDK Anthropic avec les modèles Novita AI étape par étape.

### 1. Installer le SDK Anthropic

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

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

### 2. Initialiser le client

Les SDK Anthropic sont conçus pour récupérer la clé API et l’URL de base depuis les variables d’environnement : `ANTHROPIC_API_KEY` et `ANTHROPIC_BASE_URL`. Vous pouvez également fournir les paramètres au client Anthropic lors de son initialisation.

<Tip>
  Vous pouvez consulter et gérer vos clés API sur la [page des paramètres](https://novita.ai/settings/key-management?utm_source=getstarted).
</Tip>

* Utilisation des variables d’environnement

<CodeGroup>
  ```bash Bash icon="terminal" theme={"system"}
  export ANTHROPIC_BASE_URL="https://api.novita.ai/anthropic"
  export ANTHROPIC_API_KEY="<YOUR_NOVITA_API_KEY>"
  ```
</CodeGroup>

* Définir les paramètres lors de l’initialisation du client Anthropic

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

  client = anthropic.Anthropic(
      base_url="https://api.novita.ai/anthropic",
      api_key="<YOUR_NOVITA_API_KEY>",
      # Rewrite header
      default_headers={
          "Content-Type": "application/json",
          "Authorization": "Bearer <YOUR_NOVITA_API_KEY>",
      }
  )
  ```

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

  const anthropic = new Anthropic({
      baseURL: "https://api.novita.ai/anthropic",
      apiKey: "<YOUR_NOVITA_API_KEY>",
      // Rewrite header
      defaultHeaders: {
        "Content-Type": "application/json",
        Authorization: `Bearer <YOUR_NOVITA_API_KEY>`,
      }
  });
  ```
</CodeGroup>

### 3. Appeler l’API

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

  # Initialize the client, if you already set `ANTHROPIC_BASE_URL` and `ANTHROPIC_API_KEY` 
  # in the environment variables, you can omit the `api_key` and `base_url` parameters.
  client = anthropic.Anthropic(
      base_url="https://api.novita.ai/anthropic",
      api_key="<YOUR_NOVITA_API_KEY>",
      # Rewrite header
      default_headers={
          "Content-Type": "application/json",
          "Authorization": "Bearer <YOUR_NOVITA_API_KEY>",
      }
  )

  message = client.messages.create(
      model="moonshotai/kimi-k2-instruct",
      max_tokens=1000,
      temperature=1,
      system=[
          {
              "type": "text",
              "text": "You are a world-class poet. Respond only with short poems."
          }
      ],
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "text",
                      "text": "Why is the ocean salty?"
                  }
              ]
          }
      ]
  )

  print(message.content)
  ```

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

  // Initialize the client, if you already set `ANTHROPIC_BASE_URL` and `ANTHROPIC_API_KEY` 
  // in the environment variables, you can omit the `baseURL` and `apiKey` parameters.
  const anthropic = new Anthropic({
      baseURL: "https://api.novita.ai/anthropic",
      apiKey: "<YOUR_NOVITA_API_KEY>",
      // Rewrite header
      defaultHeaders: {
        "Content-Type": "application/json",
        Authorization: `Bearer <YOUR_NOVITA_API_KEY>`,
      }
  });

  const msg = await anthropic.messages.create({
    model: "moonshotai/kimi-k2-instruct",
    max_tokens: 1000,
    temperature: 1,
    system="You are a world-class poet. Respond only with short poems.",
    messages: [
      {
        role: "user",
        content: [
          {
            type: "text",
            text: "Why is the ocean salty?"
          }
        ]
      }
    ]
  });

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