メインコンテンツへスキップ
SambaNova は、Python および JavaScript/TypeScript 向けに SDK を提供しています。これにより、SambaNova の REST API との連携が容易になります。SambaNova Python クライアント は Python 3.8 以降に対応しており、JavaScript/TypeScript 版 はサーバーサイド環境向けに設計されています。どちらのライブラリにも、リクエストパラメータやレスポンスフィールドの型定義が組み込まれており、同期・非同期の両方の利用をサポートしています。

使用例

まずは、使用したいプログラミング言語を選択してください。次に、ターミナルを開いて 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
プログラムを実行すると、以下のような出力が表示されるはずです。
{
  "id": "d89243f2-de68-416f-85c6-27c244cf9c7f",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "One day, a little girl named Sophie found a lost puppy in her neighborhood and decided to take care of it until she could find its owner. As she cared for the puppy, named Max, they formed an unbreakable bond, and when the owner was finally found, they were so grateful to Sophie that they asked her to be Max's permanent dog-sitter, bringing joy and companionship to Sophie's life.",
        "role": "assistant"
      },
      "logprobs": null
    }
  ],
  "created": 1759518870.892972,
  "model": "Meta-Llama-3.3-70B-Instruct",
  "object": "chat.completion",
  "system_fingerprint": "fastcoe",
  "usage": {
    "completion_tokens": 84,
    "prompt_tokens": 49,
    "total_tokens": 133,
    ...
    "stop_reason": "stop"
  }
}