本文へスキップ
ドキュメントのナビゲーション: オープンモデル / 追加の推論クライアント

追加の推論クライアント

RightNow AIオープンモデル追加の推論クライアント 更新日

このページの内容

モデルハブの推論クライアントは 2 つあり、Python 用の huggingface_hub と JavaScript 用の @huggingface/inference です。どちらも chat 互換のベース URL を受け付けるため、今日どちらからもオープンモデル API を呼び出せます。

hub clients
Text
Illustration of the address each model hub client takes.

Both clients take an address. The Python client takes base_url, with the base URL that ends in /v1. The JavaScript client takes endpointUrl, with the host: the client adds /v1/chat/completions itself. Naming the open models as a provider does not resolve: they are not a registered inference provider in the model hub.

Python

Shell
pip install "huggingface_hub>=1.0"
export RIGHTNOW_API_KEY="rp_your_key_here"
Python
import os
from huggingface_hub import InferenceClient

client = InferenceClient(
    base_url="https://api.rightnowai.co/v1",
    api_key=os.environ["RIGHTNOW_API_KEY"],
)

prompt = "Write a TypeScript retry helper."
completion = client.chat.completions.create(
    model="MODEL_ID",
    messages=[{"role": "user", "content": prompt}],
    max_tokens=16384,
)

print(completion.choices[0].message.content)

MODEL_ID を ライブの一覧にある ID に置き換えます。これらのクライアントは通常、モデルハブのリポジトリ ID を受け取ります。このページのベース URL の形式では、オープンモデル API と直接やり取りするため、オープンモデルの ID を渡します。

ストリーミングは stream=True を付けた同じ呼び出しで、chunk.choices[0].delta.content を読み、choices のない使用量のフレームは読み飛ばします。

JavaScript

キーを token として渡し、クライアントのオプションで endpointUrl を指定します。ホストは /v1 があってもなくても動きます。

Shell
npm install @huggingface/inference
export RIGHTNOW_API_KEY="rp_your_key_here"
Text
import { InferenceClient } from "@huggingface/inference";

const token = process.env.RIGHTNOW_API_KEY;
const client = new InferenceClient(token, {
  endpointUrl: "https://api.rightnowai.co",
});

const prompt = "Write a TypeScript retry helper.";
const completion = await client.chatCompletion({
  model: "MODEL_ID",
  messages: [{ role: "user", content: prompt }],
  max_tokens: 16384,
});

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

chatCompletionStream は同じ引数を受け取り、デルタを返します。

Warning

endpointUrl を、明示的に指定した外部プロバイダーの provider と組み合わせないでください。クライアントはその組み合わせを Cannot use endpointUrl with a third-party provider で拒否します。endpointUrl だけを渡してください。

モデルの機能

動作する JSON の例は 構造化出力 にあります。モデルが JSON 出力のために特定の reasoning_effort を必要とする場合、そのフィールドを省略するとゲートウェイが適用します。リクエストが指定しなかった強さをゲートウェイが選んだときは、レスポンスヘッダー X-RunInfra-Reasoning-Effort-Applied が適用された値を示します。

一時的に停止中のモデルは、モデルの一覧とそのオープンモデルのページに示されます。

モデルの推論が届く場所

それぞれのページで説明している推論モデルでは、モデルは答える前に考えます。そのテキストは delta.reasoning で流れ、message.reasoning に現れます。content には決して現れません。

response.json
JSON
{
  "id": "chatcmpl-example",
  "object": "chat.completion",
  "model": "glm-5-3",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "reasoning": "The user wants a retry helper. I should use exponential backoff...",
        "content": "export async function retry<T>(fn: () => Promise<T>, attempts = 3) { ... }"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 14, "completion_tokens": 892, "total_tokens": 906 }
}

この例の ID、テキスト、トークン数は説明用です。

どのクライアントを使うか

すでにモデルハブのエコシステムの中で暮らしているなら、このページのクライアントはそのまま動き、ここは後で変わりません。そうでなければ、chat API のクライアントを使ってください。これが最短の道で、これらのドキュメントの残りもそれを前提にしています。互換クライアントを参照してください。

どちらの場合も、これらの呼び出しはオープンモデル API へのほかの呼び出しと同じように課金されます。料金とクレジットとレート制限を参照してください。