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

# SambaNova クイックスタート

わずか数分で SambaNova API の利用を開始できます。

## 前提条件

作業を始める前に、以下の環境を準備してください。

* [SambaCloud](https://cloud.sambanova.ai) のアカウント、またはシステム管理者を通じた SambaStack 環境へのアクセス。
* 利用したい連携方法に応じて、Python 3、Node.js、または curl のインストール。

<Steps>
  <Step title="API キーの取得">
    API キーを生成するには、[API キーと URL](/docs/ja/get-started/api-keys-urls) のページにアクセスしてください。API キーは生成後に再表示できないため、必ず安全な場所に保存してください。

    <Note>
      最大 25 個の API キーを生成・利用できます。
    </Note>
  </Step>

  <Step title="モデルの選択">
    SambaCloud を利用する開発者は、[SambaCloud モデル](/docs/ja/models/sambacloud-models) のページで利用可能なモデルとその詳細を確認できます。

    SambaStack を利用する開発者は、システム管理者に問い合わせて、システム上で利用可能なモデルを確認してください。モデルの詳細は [SambaStack モデル](/docs/ja/sambastack/service-administration/model-deployment/supported-models-and-bundles) のページで確認できます。

    <Tip>
      本ガイドの以降のステップでは、例として `Meta-Llama-3.3-70B-Instruct` を使用します。
    </Tip>
  </Step>

  <Step title="API リクエストの送信">
    推論リクエストの送信方法は複数あります。以下に 3 つの例を示します。

    * **SambaNova SDK** - Javascript または Python 向けのネイティブな SambaNova SDK を使用します。
    * **OpenAI クライアントライブラリ** – すでに OpenAI SDK をお使いの場合は、Javascript または Python 向けの OpenAI 互換クライアントを使用します。
    * **CURL コマンド** – コマンドラインから直接リクエストを送信できます。
  </Step>
</Steps>

## SambaNova SDK

まず、使用するプログラミング言語を選択します。次に、ターミナルを開き、以下のコマンドを実行して SambaNova SDK をインストールします。

<CodeGroup>
  ```javascript Javascript theme={}
  //ensure you have Node.js installed.
  npm install sambanova
  ```

  ```python Python theme={}
  # make sure you have Python3 and pip installed
  pip install sambanova
  ```
</CodeGroup>

次に、以下のコードを新しいファイルにコピーします。

<CodeGroup>
  ```javascript hello-world.js theme={}
  import SambaNova from "sambanova";

  const client = new SambaNova({
    baseURL: "your-sambanova-base-url",
    apiKey: "your-sambanova-api-key",
  });

  const chatCompletion = await client.chat.completions.create({
    messages: [
      { role: "system", content: "Answer the question in a couple sentences." },
      { role: "user", content: "Share a happy story with me" },
    ],
    model: "Meta-Llama-3.3-70B-Instruct",
  });

  console.log(chatCompletion.choices[0].message.content);
  ```

  ```python hello_world.py theme={}
  from sambanova import SambaNova

  client = SambaNova(
      base_url="your-sambanova-base-url",
      api_key="your-sambanova-api-key"
  )

  completion = client.chat.completions.create(
    model="Meta-Llama-3.3-70B-Instruct",
    messages = [
        {"role": "system", "content": "Answer the question in a couple sentences."},
        {"role": "user", "content": "Share a happy story with me"}
      ]
  )

  print(completion.choices[0].message.content)
  ```
</CodeGroup>

コードをファイルにコピーしたら、プレースホルダ文字列 `"your-sambanova-base-url"` と `"your-sambanova-api-key"` を、実際のベース URL と API キーに置き換えます。その後、以下のコマンドを使用してターミナルでファイルを実行します。

<CodeGroup>
  ```javascript Javascript theme={}
  node hello-world.js
  ```

  ```python Python theme={}
  python hello_world.py
  ```
</CodeGroup>

プログラムを実行すると、以下のような出力が表示されます。

```
Here’s a happy story: One day, a little girl named Sophie found a lost puppy in her neighborhood and decided to take it home to care for it. As she nursed the puppy back to health, she named it Max and the two became inseparable best friends, going on adventures and playing together every day.
```

## OpenAI クライアントライブラリ

まず、使用するプログラミング言語を選択します。次に、ターミナルウィンドウを開き、以下のコマンドを実行して OpenAI ライブラリをインストールします。

<CodeGroup>
  ```javascript Javascript theme={}
  //ensure you have Node.js installed.
  npm install openai
  ```

  ```python Python theme={}
  # make sure you have Python3 and pip installed
  pip install openai
  ```
</CodeGroup>

次に、以下のコードを新しいファイルにコピーします。

<CodeGroup>
  ```javascript hello-world.js theme={}
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: "your-sambanova-base-url",
    apiKey: "your-sambanova-api-key",
  });

  const chatCompletion = await client.chat.completions.create({
    messages: [
      { role: "system", content: "Answer the question in a couple sentences." },
      { role: "user", content: "Share a happy story with me" },
    ],
    model: "Meta-Llama-3.3-70B-Instruct",
  });

  console.log(chatCompletion.choices[0].message.content);
  ```

  ```python hello_world.py theme={}
  from openai import OpenAI

  client = OpenAI(
      base_url="your-sambanova-base-url",
      api_key="your-sambanova-api-key"
  )

  completion = client.chat.completions.create(
    model="Meta-Llama-3.3-70B-Instruct",
    messages = [
        {"role": "system", "content": "Answer the question in a couple sentences."},
        {"role": "user", "content": "Share a happy story with me"}
      ]
  )

  print(completion.choices[0].message.content)
  ```
</CodeGroup>

コードをファイルにコピーしたら、文字列フィールド `"your-sambanova-base-url"` と `"your-sambanova-api-key"` を、実際のベース URL と API キーの値に置き換えます。その後、ターミナルウィンドウで以下のコマンドを使用してファイルを実行します。

<CodeGroup>
  ```javascript Javascript theme={}
  node hello-world.js
  ```

  ```python Python theme={}
  python hello_world.py
  ```
</CodeGroup>

プログラムを実行すると、以下のような出力が表示されます。

```
Here’s a happy story: One day, a little girl named Sophie found a lost puppy in her neighborhood and decided to take it home to care for it. As she nursed the puppy back to health, she named it Max and the two became inseparable best friends, going on adventures and playing together every day.
```

## CURL コマンド

ターミナルウィンドウで以下の CURL コマンドを実行し、API への最初のリクエストを送信します。

```sh theme={}
export API_KEY="your-api-key-here"
export URL="your-url-here"

curl -H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "system", "content": "Answer the question in a couple sentences."},
{"role": "user", "content": "Share a happy story with me"}
],
"stop": ["<|eot_id|>"],
"model": "Meta-Llama-3.3-70B-Instruct",
"stream": true, "stream_options": {"include_usage": true}
}' \
-X POST $URL
```

## 次のステップ

これでモデルへのリクエストができるようになりました。次は、AI を活用したアプリケーションの構築に挑戦してみましょう。オープンソースの Python プロジェクト集である [AI スターターキット](/docs/ja/build/ai-starter-kits) を参考に、開発のアイデアを見つけてください。
