メインコンテンツへスキップ
POST
/
chat
/
completions
Create chat completion
curl --request POST \
  --url https://dimilinks.com/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "claude-sonnet-5",
  "messages": [
    {
      "content": "<string>",
      "name": "<string>",
      "tool_call_id": "<string>"
    }
  ],
  "stream": false,
  "temperature": 123,
  "top_p": 123,
  "max_tokens": 123,
  "stop": "<string>",
  "presence_penalty": 123,
  "frequency_penalty": 123,
  "tools": [
    {}
  ],
  "tool_choice": "<string>",
  "response_format": {},
  "user": "<string>"
}
'
import requests

url = "https://dimilinks.com/v1/chat/completions"

payload = {
"model": "claude-sonnet-5",
"messages": [
{
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>"
}
],
"stream": False,
"temperature": 123,
"top_p": 123,
"max_tokens": 123,
"stop": "<string>",
"presence_penalty": 123,
"frequency_penalty": 123,
"tools": [{}],
"tool_choice": "<string>",
"response_format": {},
"user": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'claude-sonnet-5',
messages: [{content: '<string>', name: '<string>', tool_call_id: '<string>'}],
stream: false,
temperature: 123,
top_p: 123,
max_tokens: 123,
stop: '<string>',
presence_penalty: 123,
frequency_penalty: 123,
tools: [{}],
tool_choice: '<string>',
response_format: {},
user: '<string>'
})
};

fetch('https://dimilinks.com/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://dimilinks.com/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'claude-sonnet-5',
'messages' => [
[
'content' => '<string>',
'name' => '<string>',
'tool_call_id' => '<string>'
]
],
'stream' => false,
'temperature' => 123,
'top_p' => 123,
'max_tokens' => 123,
'stop' => '<string>',
'presence_penalty' => 123,
'frequency_penalty' => 123,
'tools' => [
[

]
],
'tool_choice' => '<string>',
'response_format' => [

],
'user' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://dimilinks.com/v1/chat/completions"

payload := strings.NewReader("{\n \"model\": \"claude-sonnet-5\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"stream\": false,\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"stop\": \"<string>\",\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\",\n \"response_format\": {},\n \"user\": \"<string>\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://dimilinks.com/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"claude-sonnet-5\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"stream\": false,\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"stop\": \"<string>\",\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\",\n \"response_format\": {},\n \"user\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://dimilinks.com/v1/chat/completions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"claude-sonnet-5\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"stream\": false,\n \"temperature\": 123,\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"stop\": \"<string>\",\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\",\n \"response_format\": {},\n \"user\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "id": "chatcmpl_xxx",
  "object": "chat.completion",
  "created": 1777080000,
  "model": "claude-sonnet-5",
  "choices": [
    {
      "index": 123,
      "message": {
        "content": "<string>",
        "name": "<string>",
        "tool_call_id": "<string>"
      },
      "finish_reason": "<string>"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  }
}
{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}
{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}
{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}
{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>"
}
}
/v1/chat/completions は、DimiLinks が推奨する対話用エンドポイントです。リクエストとレスポンスの構造は OpenAI 公式 API と同一で、OpenAI SDK をそのまま使用できます。model を現在のキーで利用可能なテキストモデル名に変更するだけで、Claude、GPT などのモデルを呼び出せます。

リクエスト URL

POST https://dimilinks.com/v1/chat/completions
Content-Type: application/json
Authorization: Bearer <DIMILINKS_API_KEY>

基本的な例

curl "https://dimilinks.com/v1/chat/completions" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5",
    "messages": [
      {"role": "system", "content": "あなたは簡潔に答える日本語アシスタントです。"},
      {"role": "user", "content": "冥王星とは何か、一文で説明してください。"}
    ]
  }'
レスポンス(抜粋):
{
  "id": "chatcmpl_xxx",
  "object": "chat.completion",
  "created": 1777080000,
  "model": "claude-sonnet-5",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "..." },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 32,
    "completion_tokens": 24,
    "total_tokens": 56
  }
}

ストリーミング出力

リクエストに "stream": true を追加すると、サーバーは text/event-stream で差分チャンクを返し、最後に data: [DONE] を送信して終了します。
curl "https://dimilinks.com/v1/chat/completions" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "gpt-5.5",
    "stream": true,
    "messages": [
      {"role": "user", "content": "深海をテーマにした四行の短い詩を書いてください"}
    ]
  }'
各イベントの構造:
data: {"id":"chatcmpl_xxx","object":"chat.completion.chunk","model":"gpt-5.5",
"choices":[{"index":0,"delta":{"content":"深"},"finish_reason":null}]}

パラメータ

よく使われるフィールドのみを記載しています。記載されていないフィールドも、モデルが対応していればそのままアップストリームへ渡されます。
パラメータデフォルト値説明
modelstring必須モデル ID。例:claude-sonnet-5claude-opus-4-8gpt-5.5gpt-5.6-terraqwen3.7-max など。
messagesarray必須メッセージ配列。少なくとも 1 件の role=user を含める必要があります。rolesystem / user / assistant / tool に対応しています。
streambooleanfalsetrue の場合、SSE ストリーミングチャンクを返します。
temperaturenumberモデルのデフォルトサンプリング温度。0〜2。
top_pnumberモデルのデフォルトnucleus sampling の確率。0〜1。
max_tokensintegerモデルのデフォルト1 回の出力で生成する最大 token 数。Claude 系モデルを呼び出す場合は明示的な指定を推奨します。
stopstring | string[]指定した文字列に一致すると生成を停止します。
presence_penaltynumber0同じ話題の繰り返しに対するペナルティ。-2〜2。
frequency_penaltynumber0同じ単語の繰り返しに対するペナルティ。-2〜2。
toolsarrayツール呼び出しの定義。OpenAI Tool Calling と互換性のある構造です。
tool_choicestring | objectauto特定のツールを強制的に呼び出すかどうかを制御します。
response_formatobjectJSON 出力を要求します。例:{ "type": "json_object" }
userstring監査やレート制限に使用するエンドユーザー識別子。

推奨モデル

ユースケースモデル
汎用対話 / 長文ドキュメントclaude-sonnet-5claude-opus-4-8gpt-5.5
複雑な推論 / コーディングclaude-opus-4-8kimi-k2.7-codegpt-5.6-terra
日本語・中国語などの汎用タスクqwen3.7-maxglm-5.2MiniMax-M3
低コストの一括処理claude-haiku-4-5gpt-5.4-minideepseek-v4-flash
マルチモーダルビジョンgpt-image-2(画像生成専用)。視覚対話への対応はモデルによって異なるため、まず /v1/modelsinput_modalities を確認してください。

OpenAI SDK での呼び出し

Python:
from openai import OpenAI

client = OpenAI(
    api_key="sk-...",
    base_url="https://dimilinks.com/v1",
)

response = client.chat.completions.create(
    model="claude-sonnet-5",
    messages=[
        {"role": "system", "content": "あなたは正確に答える日本語アシスタントです。"},
        {"role": "user", "content": "フーリエ変換について説明してください。"},
    ],
    max_tokens=1024,
)

print(response.choices[0].message.content)
Node.js:
import OpenAI from 'openai'

const client = new OpenAI({
  apiKey: process.env.DIMILINKS_API_KEY,
  baseURL: 'https://dimilinks.com/v1',
})

const response = await client.chat.completions.create({
  model: 'gpt-5.5',
  messages: [{ role: 'user', content: 'こんにちは' }],
})

ツール呼び出し (Tool calling)

curl "https://dimilinks.com/v1/chat/completions" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5",
    "messages": [
      {"role": "user", "content": "東京の現在の天気を調べてください"}
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "指定した都市の現在の天気を取得する",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {"type": "string"}
            },
            "required": ["city"]
          }
        }
      }
    ]
  }'
モデルから tool_calls が返されたら、ツールの実行結果を role=tool のメッセージとして messages に追加し、再度呼び出してください。

エラー処理

リクエストに失敗すると、OpenAI 形式の error ラッパーが返されます。詳細は エラー を参照してください。ストリーミングリクエスト中にアップストリーム接続が切れた場合、最後のイベントが [DONE] にならないことがあります。「接続切断」も再試行可能なエラーとして扱うことを推奨します。

承認

Authorization
string
header
必須

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

ボディ

application/json
model
string
必須
:

"claude-sonnet-5"

messages
object[]
必須
stream
boolean
デフォルト:false
temperature
number
top_p
number
max_tokens
integer
stop
presence_penalty
number
frequency_penalty
number
tools
object[]
tool_choice
response_format
object
user
string

レスポンス

Chat completion result. When stream is true the response is text/event-stream.

id
string
:

"chatcmpl_xxx"

object
string
:

"chat.completion"

created
integer
:

1777080000

model
string
:

"claude-sonnet-5"

choices
object[]
usage
object