NEXGATE AIdocs コンソール

API

ベースURL
https://api.nexgate.space
認証
Authorization: Bearer ngx_… / x-api-key: ngx_…
トークン発行
https://console.nexgate.space/dash/tokens

OpenAI 互換(/v1/chat/completions)と Anthropic 互換(/v1/messages)の 両方を提供しています。同じトークンでどちらも呼び出せます。

エンドポイント

GET/v1/models
モデル一覧。type は text / image / ocr。
POST/v1/chat/completions
テキスト生成(OpenAI 互換)。
パラメータ: model(必須)/ messages(必須)/ stream / temperature / top_p / max_tokens / tools / tool_choice
POST/v1/messages
テキスト生成(Anthropic 互換)。x-api-key と anthropic-version を そのまま使えます。
パラメータ: model(必須)/ messages(必須)/ max_tokens(必須)/ system / stream / temperature / top_p / stop_sequences / tools(input_schema)/ tool_choice
POST/v1/messages/count_tokens
入力トークン数の見積もり。レスポンスは { "input_tokens": N }。
POST/v1/images/generations
画像生成(OpenAI 互換)。
パラメータ: model / prompt(必須)/ size(1024x1024 形式、256〜2048)/ n(1〜4)
レスポンス: { "created": …, "data": [{ "url": … }] }
POST/v1/ocr
画像内の文字をテキスト化。
パラメータ: model / image_url(必須、data URL のみ)/ engine(ai / local)
外部URLからの取得には対応していません。
POST/v1/audio/speech
音声生成(TTS)。OpenAI の /v1/audio/speech と同じ形で、レスポンスは WAV バイナリ。
パラメータ: model / input(必須、最大 1000 文字)/ voice(話者IDまたは名前、省略時は 3)/ response_format(wav のみ)/ speed
GET/v1/audio/voices
利用可能な話者一覧。レスポンスの voices に、実際に指定できる話者の ID・名前が入っています(data.speakers は提供元の全一覧で、 available が true のものだけが利用できます)。

SDK から使う

base_url を差し替えるだけで、公式 SDK がそのまま使えます。

OpenAI SDK (Python)
from openai import OpenAI

client = OpenAI(base_url="https://api.nexgate.space/v1", api_key="ngx_YOUR_TOKEN")

resp = client.chat.completions.create(
    model="MODEL_ID",
    messages=[{"role": "user", "content": "こんにちは"}],
)
print(resp.choices[0].message.content)
Anthropic SDK (Python)
from anthropic import Anthropic

client = Anthropic(base_url="https://api.nexgate.space", api_key="ngx_YOUR_TOKEN")

resp = client.messages.create(
    model="MODEL_ID",
    max_tokens=1024,
    messages=[{"role": "user", "content": "こんにちは"}],
)
print(resp.content[0].text)

リクエスト例

テキスト生成(OpenAI 互換)
curl https://api.nexgate.space/v1/chat/completions \
  -H "Authorization: Bearer ngx_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nexgate-high",
    "messages": [{"role": "user", "content": "こんにちは"}]
  }'
テキスト生成(Anthropic 互換)
curl https://api.nexgate.space/v1/messages \
  -H "x-api-key: ngx_YOUR_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nexgate-high",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "こんにちは"}]
  }'
画像生成
curl https://api.nexgate.space/v1/images/generations \
  -H "Authorization: Bearer ngx_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nexgate-image-pro",
    "prompt": "夕暮れの東京の街並み",
    "size": "1024x1024"
  }'
文字認識(OCR)
curl https://api.nexgate.space/v1/ocr \
  -H "Authorization: Bearer ngx_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nexgate-ocr-lite",
    "image_url": "data:image/png;base64,……"
  }'
音声生成(TTS)
curl https://api.nexgate.space/v1/audio/speech \
  -H "Authorization: Bearer ngx_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nexgate-voice",
    "input": "こんにちは、NEXGATE AIです。",
    "voice": "3"
  }' --output hello.wav

レスポンス例

/v1/chat/completions

{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "model": "nexgate-high",
  "choices": [
    { "index": 0, "message": { "role": "assistant", "content": "こんにちは" }, "finish_reason": "stop" }
  ],
  "usage": { "prompt_tokens": 12, "completion_tokens": 8, "total_tokens": 20 }
}

/v1/messages

{
  "id": "msg_…",
  "type": "message",
  "role": "assistant",
  "model": "nexgate-high",
  "content": [{ "type": "text", "text": "こんにちは" }],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": { "input_tokens": 12, "output_tokens": 8 }
}

エラー

/v1/chat/completions などは { "error": { "message", "type", "code" } }、 /v1/messages は Anthropic と同じ { "type": "error", "error": { "type", "message" } } で返します。

ステータスcode内容
400invalid_request_errorリクエストの形式が不正。
401invalid_api_keyトークンが無効。
403permission_errorAPIアクセス無効、またはプラン対象外(insufficient_quota / image_generation_not_allowed / ocr_not_allowed)。
429rate_limit_exceededレート制限超過。Retry-After 秒後に再試行。
502provider_error上流でエラー。
503overloaded同時実行の上限に達している。

CORS

/v1/* は CORS に対応。Authorization と Content-Type を許可。