API Reference
teai.io LLM API Gateway -- OpenAI互換のユニファイドAPIで、GPT-4o、Claude、Gemini、その他多数のモデルに単一エンドポイントからアクセスできます。既存のOpenAI SDKをそのまま使用可能です。
Base URL
すべてのAPIリクエストはHTTPS経由で上記ベースURLに送信します。HTTPリクエストはHTTPSにリダイレクトされます。
Authentication
APIリクエストにはAPIキーが必要です。Authorization ヘッダーにBearerトークンとして渡します。
Authorization: Bearer te_your_api_key_here
APIキーは cw_ または te_ で始まります。ダッシュボードまたは APIキー作成エンドポイント から発行できます。
Chat Completions
指定したモデルでチャット応答を生成します。OpenAI Chat Completions APIと完全互換です。
Request Body
| Parameter | Type | Description |
|---|---|---|
| modelREQUIRED | string | モデルID。例: gpt-4o, claude-sonnet-4-6, gemini-2.5-pro, auto |
| messagesREQUIRED | array | メッセージ配列。各要素に role (system | user | assistant | tool) と content (string) を含む |
| streamoptional | boolean | SSEストリーミングを有効化。デフォルト: false |
| temperatureoptional | number | サンプリング温度 (0-2)。デフォルト: 1.0。低いほど決定的、高いほどランダム |
| max_tokensoptional | integer | 生成する最大トークン数。デフォルトはモデル依存 |
| top_poptional | number | Nucleus sampling (0-1)。デフォルト: 1.0 |
| toolsoptional | array | 利用可能なツール定義の配列。OpenAI function calling形式 |
| tool_choiceoptional | string | ツール呼び出し制御。auto | required | none |
Request Example
{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
],
"stream": false,
"temperature": 0.7,
"max_tokens": 1024
}
Response (non-streaming)
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1710000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 8,
"total_tokens": 33
}
}
Streaming (SSE)
"stream": true を指定すると、Server-Sent Events (SSE) 形式でレスポンスがストリーミングされます。各チャンクは data: プレフィックス付きのJSON行として送信されます。
SSE Format
// 各チャンク
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" world"},"finish_reason":null}]}
// 終了シグナル
data: [DONE]
delta には role: "assistant" が含まれます。後続のチャンクには content のみが含まれます。ストリーム終了時は data: [DONE] が送信されます。
Tool Calling
OpenAI function calling形式でツールを定義し、モデルにツール呼び出しを生成させることができます。
Request with Tools
{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "What's the weather in Tokyo?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}
Response with Tool Call
{
"choices": [{
"message": {
"role": "assistant",
"content": null,
"tool_calls": [{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"Tokyo\"}"
}
}]
},
"finish_reason": "tool_calls"
}]
}
List Models
認証不要。現在利用可能なすべてのモデルとそのメタデータを返します。
Response
{
"object": "list",
"data": [
{
"id": "gpt-4o",
"object": "model",
"created": 1710000000,
"owned_by": "openai"
},
{
"id": "claude-sonnet-4-6",
"object": "model",
"created": 1710000000,
"owned_by": "anthropic"
},
{
"id": "gemini-2.5-pro",
"object": "model",
"created": 1710000000,
"owned_by": "google"
}
]
}
Models Pricing
各モデルの入力・出力トークン単価を返します(USD / 1Mトークン)。
Response
{
"models": {
"gpt-4o": {
"input_per_1m": 2.50,
"output_per_1m": 10.00
},
"claude-sonnet-4-6": {
"input_per_1m": 3.00,
"output_per_1m": 15.00
},
"gemini-2.5-pro": {
"input_per_1m": 1.25,
"output_per_1m": 5.00
}
}
}
API Keys
新しいAPIキーを作成します。キーは作成時のみ全文が返されます。
Request Body
| Parameter | Type | Description |
|---|---|---|
| nameoptional | string | APIキーの名前(管理用) |
Response
{
"id": "key_abc123",
"name": "My API Key",
"key": "te_sk_live_xxxxxxxxxxxxxxxxxxxx",
"created_at": "2026-03-10T00:00:00Z"
}
自分のAPIキー一覧を取得します。キーはマスクされた状態で返されます。
Response
{
"keys": [
{
"id": "key_abc123",
"name": "My API Key",
"key_preview": "te_sk_...xxxx",
"created_at": "2026-03-10T00:00:00Z",
"last_used_at": "2026-03-10T12:34:56Z"
}
]
}
指定したAPIキーを無効化・削除します。削除後は即座に認証に使用できなくなります。
Path Parameters
| Parameter | Type | Description |
|---|---|---|
| idREQUIRED | string | 削除するAPIキーのID |
Response
{
"deleted": true,
"id": "key_abc123"
}
Account Info
認証済みユーザーのアカウント情報とクレジット残高を返します。
Response
{
"user_id": "usr_abc123",
"email": "user@example.com",
"plan": "pro",
"credits_remaining": 4250,
"created_at": "2026-01-15T00:00:00Z"
}
Error Codes
APIはエラー時に統一されたJSON形式でレスポンスを返します。
Error Response Format
{
"error": {
"type": "rate_limit_exceeded",
"message": "Rate limit exceeded. Retry after 30 seconds.",
"retry_after": 30
}
}
Error Code Reference
| HTTP | error.type | Description | Action |
|---|---|---|---|
| 400 | invalid_request | リクエスト形式不正 | パラメータを確認 |
| 401 | authentication_error | APIキー無効 | APIキーを確認・再発行 |
| 402 | insufficient_credits | クレジット残高不足 | クレジットを追加購入 |
| 404 | model_not_found | 指定モデルが存在しない | /v1/models で確認 |
| 429 | rate_limit_exceeded | レート制限超過 | Retry-After ヘッダーに従う |
| 500 | internal_error | サーバー内部エラー | リトライ(エクスポネンシャルバックオフ) |
| 502 | upstream_error | 上流プロバイダーエラー | 別モデルを試す or リトライ |
| 503 | service_unavailable | メンテナンス中 | ステータスページを確認 |
Rate Limits
プランごとにレート制限が設定されています。制限超過時はエラーレスポンスが返されます。
Plan Limits
| Plan | Requests/hour | Requests/day |
|---|---|---|
| Guest (未認証) | 30 | 30 |
| Free (認証済み) | 120 | 500 |
| Pro | 120 | 30,000 |
| Business | カスタム | 無制限 |
レート制限超過時はJSONエラーレスポンスが返されます。適切な間隔をあけてリトライしてください。
Timeouts
クライアント実装時に考慮すべきタイムアウト値:
| Type | Duration | Description |
|---|---|---|
| Connection | 10 seconds | TCP接続確立のタイムアウト |
| Request (non-streaming) | 60 seconds | 非ストリーミングリクエストのレスポンスタイムアウト |
| Request (streaming) | 120 seconds | ストリーミングリクエストの全体タイムアウト |
| Idle (SSE) | 30 seconds | 最後のチャンク送信からのアイドルタイムアウト |
Model Versioning
モデルIDの解決ルールとバージョン管理ポリシーについて説明します。
| Feature | Description |
|---|---|
| Latest alias | モデルID(例: gpt-4o)はプロバイダーの最新安定版を指す |
| Pinned version | 特定バージョン固定: gpt-4o-2024-08-06 のようにサフィックス付きIDで指定可能 |
| Changelog | バージョン変更時は Changelog で事前告知 |
| Deprecation | 旧バージョンは最低90日間サポート |
gpt-4o)は予告なくポイント先が変更される場合があります。
Failover
teai.ioはLoadBalancedProviderによるマルチプロバイダーアーキテクチャで高い可用性を実現しています。
フェイルオーバー動作
- モデルを指定した場合、そのモデルのプロバイダーに接続。障害時はティア内の次のモデルにフェイルオーバー
- サーキットブレーカー + ラウンドロビンでプロバイダー障害を自動検知・迂回
- Nemotron 9B(セルフホスト)が全プロバイダー障害時の最終フォールバック
レスポンスの model フィールド
レスポンスボディのmodelフィールドに実際に使用されたモデル名が返されます。リクエストしたモデルと異なる場合、フェイルオーバーが発生したことを意味します。
SDK Examples
teai.ioはOpenAI互換APIのため、既存のOpenAI SDKをそのまま使用できます。ベースURLを変更するだけで接続可能です。
from openai import OpenAI
client = OpenAI(
base_url="https://api.teai.io/v1",
api_key="te_xxx",
)
# Streaming example
resp = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
stream=True,
)
for chunk in resp:
print(chunk.choices[0].delta.content or "", end="")
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.teai.io/v1',
apiKey: 'te_xxx',
});
// Streaming example
const stream = await client.chat.completions.create({
model: 'claude-sonnet-4-6',
messages: [{ role: 'user', content: 'Hello' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
package main
import (
"context"
"fmt"
openai "github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig("te_xxx")
config.BaseURL = "https://api.teai.io/v1"
client := openai.NewClientWithConfig(config)
resp, _ := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: "gpt-4o",
Messages: []openai.ChatCompletionMessage{
{Role: "user", Content: "Hello"},
},
},
)
fmt.Println(resp.Choices[0].Message.Content)
}
// Using OpenAI Java SDK with custom base URL
OpenAIClient client = OpenAIOkHttpClient.builder()
.baseUrl("https://api.teai.io/v1")
.apiKey("te_xxx")
.build();
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
.model("gpt-4o")
.addUserMessage("Hello")
.build();
client.chat().completions().create(params)
.choices().forEach(c ->
System.out.println(c.message().content()));
# Non-streaming
curl https://api.teai.io/v1/chat/completions \
-H "Authorization: Bearer te_xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello"}]
}'
# Streaming
curl https://api.teai.io/v1/chat/completions \
-H "Authorization: Bearer te_xxx" \
-H "Content-Type: application/json" \
-N \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello"}],
"stream": true
}'