機能別

チャット

モデルを選び、リクエストをコピーして、返答を読みます。すべてのチャットモデルは同じ OpenAI 形式のリクエストを受け付けます。

#1. モデルを選ぶ

gpt-6-luna入力 $0.10 · 出力 $0.50 / 1M制限とステータス

この用途で稼働中のモデルは 5 個です。切り替えると下のコードが変わります。

#2. リクエストをコピー

YOUR_API_KEY を自分のキーに置き換えて実行します。表示されているオプションは、このモデルが受け付けるものです。

POSThttps://www.aisplice.store/v1/chat/completionsBearer API key即時応答
API_KEY="${API_KEY:-YOUR_API_KEY}"

curl --fail-with-body -sS https://www.aisplice.store/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "GPT-6 Luna",
  "messages": [
    {
      "role": "user",
      "content": "Say hello."
    }
  ],
  "stream": false
}'

すべてのパラメーター

このモデルが受け付けるすべてのフィールドと、指定できる値。

model
string必須

このリクエストで使う正確なモデル識別子。

messages
array任意

Required on /v1/chat/completions.

input
string|array任意

Required on /v1/responses.

レスポンスの流れ

このエンドポイントの成功レスポンスの例。

レスポンス
{
  "id": "chatcmpl_xxx",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Hello!"
      }
    }
  ]
}

すべてのフィールド:API リファレンスの /v1/chat/completions →

#3. 結果を取得

200 の応答では、返答が choices[0].message.content に入っています。生成中に受け取るには "stream": true を追加します。

#うまくいかないとき

  • フィールド名付きの 400:そのオプションはこのモデルでは受け付けられません。手順 2 に表示される値を使ってください。
  • 402:残高がこのリクエストに足りません。ウォレットでチャージしてから再試行してください。
  • 429:ペースを落とし、Retry-After の秒数が経ってから再試行してください。
  • 503 model_not_found:モデル名が間違っているか、モデルがオフラインです。手順 1 から選び直してください。

その他のエラーを調べる →

ストリーミング返答を生成しながら表示します。

#仕組み

stream:true を設定すると、ゲートウェイは OpenAI が送出するとおりに Server-Sent Events を中継します:差分ごとに data: フレームが 1 つ送られ、data: [DONE] で終了します。SSE クライアントや公式 SDK はそのまま利用できます。

#実行する

terminal — live
curl -N https://www.aisplice.store/v1/chat/completions \
  -H "Authorization: Bearer sk-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-luna",
    "stream": true,
    "messages": [
      {
        "role": "user",
        "content": "Write a haiku about the sea."
      }
    ]
  }'
streaming.py
from openai import OpenAI

client = OpenAI(base_url="https://www.aisplice.store/v1", api_key="sk-YOUR_KEY")

stream = client.chat.completions.create(
    model="gpt-5.6-luna",
    stream=True,
    messages=[{"role": "user", "content": "Write a haiku about the sea."}],
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

#部分課金

ストリーミングされた分だけ支払う

クライアントがストリームの途中で切断した場合、ゲートウェイは実際に送信された分の使用量を記録します — 課金されるのは届いた分だけです。
ツール呼び出しモデルに自分の関数を呼び出させます。

#ツールを宣言

標準の OpenAI の tools 配列を送信します。ゲートウェイはツール対応のすべてのモデル — OpenAI、Claude、Gemini、DeepSeek — に転送し、返答を tool_calls に正規化します。ツール呼び出しの差分のストリーミングにも対応しています。

tools.sh
curl https://www.aisplice.store/v1/chat/completions \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-luna",
    "messages": [{"role":"user","content":"Weather in Tokyo?"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "parameters": {
          "type": "object",
          "properties": {"city": {"type": "string"}},
          "required": ["city"]
        }
      }
    }]
  }'

#tool_calls を処理

モデルがツールの呼び出しを決めると、choice が finish_reason:"tool_calls" とともに返されます。arguments の文字列をコード側でパースして実行してください。

response.json
{
  "choices": [{
    "finish_reason": "tool_calls",
    "message": {
      "role": "assistant",
      "tool_calls": [{
        "id": "call_abc123",
        "type": "function",
        "function": {
          "name": "get_weather",
          "arguments": "{\"city\": \"Tokyo\"}"
        }
      }]
    }
  }]
}

#結果を返す

assistant のターンと、呼び出しごとに 1 つの role:"tool" メッセージ(tool_call_id で対応付け)を追加して、もう一度リクエストします — モデルが結果を最終的な回答に組み込みます。

round-trip.sh
curl https://www.aisplice.store/v1/chat/completions \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-luna",
    "messages": [
      {"role":"user","content":"Weather in Tokyo?"},
      {"role":"assistant","tool_calls":[{"id":"call_abc123","type":"function",
        "function":{"name":"get_weather","arguments":"{\"city\":\"Tokyo\"}"}}]},
      {"role":"tool","tool_call_id":"call_abc123","content":"{\"temp_c\": 22, \"sky\": \"clear\"}"}
    ]
  }'
画像入力テキストと一緒に画像を送ります。

#画像を送信

画像認識に対応したチャットモデルは、テキストパーツと image_url パーツを混在させた content 配列を受け付けます。公開 URL かインラインの base64 data URL を使います — どちらも同じフィールドです。

vision.sh
curl https://www.aisplice.store/v1/chat/completions \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-luna",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "What is in this image?"},
        {"type": "image_url", "image_url": {"url": "https://example.com/cat.png"}}
      ]
    }]
  }'

#Base64 画像

ローカルファイルは data URL でインライン化します:"url": "data:image/png;base64,<bytes>"。画像のトークンは入力トークンとして課金されます。1 リクエストあたりの最大画像サイズと枚数はベンダーによって異なります — コスト削減のため、送信前に縮小してください。

base64.py
import base64
from openai import OpenAI

client = OpenAI(base_url="https://www.aisplice.store/v1", api_key="sk-YOUR_KEY")
b64 = base64.b64encode(open("photo.png", "rb").read()).decode()

resp = client.chat.completions.create(
    model="gpt-5.6-luna",
    messages=[{"role": "user", "content": [
        {"type": "text", "text": "Describe this photo."},
        {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{b64}"}},
    ]}],
)
print(resp.choices[0].message.content)

まだ解決しませんか?

リクエスト ID かエラーメッセージを送っていただければ、こちらで調査します。