メインコンテンツへスキップ
わずか数分でSambaNova APIの利用を開始できます。 ###API利用のフロー
1

APIキーを取得

こちらのページの手順に従い、APIキーを発行します。キーは一度しか表示されないため、必ず安全な場所に保存してください。
最大25個のAPIキーを発行・利用できます。使用状況の確認は、Cloudポータルから行えます。
2

モデルを選択

SambaCloudを利用する開発者は、SambaCloud モデル のページにて利用可能なモデルと詳細を確認できます。 SambaStackを利用する開発者は、貴組織のシステム管理者に問い合わせて、システム上で利用可能なモデルを確認してください。モデルの詳細は SambaStack モデル ページにて確認できます。
このガイドでは、例として Meta-Llama-3.3-70B-Instruct を使用します。
3

APIリクエストを送信

推論リクエストの送信方法は以下のように複数存在します。
  • SambaNova SDK: JavascriptまたはPythonを使用して柔軟に統合可能
  • OpenAIクライアントライブラリ: JavascriptまたはPythonを使用して柔軟に統合可能
  • CURLコマンド: コマンドラインから直接リクエストを送信

SambaNova SDKを使用する場合

まず、使用するプログラミング言語を選択し、ターミナルを開いて SambaNova SDK をインストールします。
// Node.jsを事前にインストールしてください
npm install sambanova
次に、以下のコードを新しいファイルにコピーします。
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);
コードをコピーしたら、"your-sambanova-base-url" および "your-sambanova-api-key" の部分を、実際のベースURLとAPIキーに置き換えます。 次に、以下のコマンドを使用してターミナルからファイルを実行します。
node hello-world.js
プログラムを実行すると、以下のような出力が表示されます。
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ライブラリをインストールします。
// Node.jsを事前にインストールしてください
npm install openai
次に、以下のコードを新しいファイルにコピーします。
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.sambanova.ai/v1",
  apiKey: "<YOUR 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);
"<YOUR API KEY>"の部分を、実際のAPIキーに置き換えてください。その後、ターミナルウィンドウで以下のコマンドを使用して、ファイルを実行します。
node hello-world.js
実行すると、以下のような出力が表示されます。
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コマンドを使用する場合

ターミナルウィンドウで以下のコマンドを実行すると、APIへのリクエストを送信できます。
export API_KEY=<YOUR API KEY>
export URL=https://api.sambanova.ai/v1/chat/completions

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

次のステップ

これでモデルへのリクエストができるようになりました! 次は、アプリケーションの構築にチャレンジしてみましょう。 SambaNovaが提供するオープンソースのPythonプロジェクト集「AIスターターキット」 を参考に、次の開発アイディアを見つけてください。