注册

创建聊天函数调用

Chat Function Call

POST https://api.quickrouter.ai/v1/chat/completions 在线调试 →
Authorization

在 Header 添加参数 Authorization,其值为 Bearer 之后拼接 Token

示例: Authorization: Bearer ********************

请求参数

Header 参数
Content-Type string
必需
示例: application/json
Authorization string
必需
示例: Bearer $OPENAI_API_KEY
Body 参数 application/json
model string
必需
要使用的模型的 ID,如 gpt-4o。
messages array [object]
必需
至今为止对话所包含的消息列表,支持多轮对话。
tools array [object]
必需
模型可以调用的一组工具列表,目前只支持函数工具。
temperature number
可选
使用什么采样温度,介于 0 和 2 之间。
max_tokens integer
可选
生成的最大标记数。
stream boolean
可选
设置为 true 启用流式输出。
示例
{
    "model": "gpt-4o",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user."
        },
        {
            "role": "user",
            "content": "Hi, can you tell me the delivery date for my order?"
        },
        {
            "role": "assistant",
            "content": "Hi there! I can help with that. Can you please provide your order ID?"
        },
        {
            "role": "user",
            "content": "i think it is order_12345"
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_delivery_date",
                "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date of an order, for example when a customer asks 'Where is my package'",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "order_id": {
                            "type": "string",
                            "description": "The customer's order ID."
                        }
                    },
                    "required": ["order_id"],
                    "additionalProperties": false
                }
            }
        }
    ]
}

请求示例代码

curl --location --request POST 'https://api.quickrouter.ai/v1/chat/completions' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-4o",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user."
        },
        {
            "role": "user",
            "content": "Hi, can you tell me the delivery date for my order?"
        },
        {
            "role": "assistant",
            "content": "Hi there! I can help with that. Can you please provide your order ID?"
        },
        {
            "role": "user",
            "content": "i think it is order_12345"
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_delivery_date",
                "description": "Get the delivery date for a customer\'s order. Call this whenever you need to know the delivery date of an order, for example when a customer asks \'Where is my package\'",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "order_id": {
                            "type": "string",
                            "description": "The customer\'s order ID."
                        }
                    },
                    "required": ["order_id"],
                    "additionalProperties": false
                }
            }
        }
    ]
}'
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <token>");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
   "model": "gpt-4o",
   "messages": [
      {
         "role": "system",
         "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user."
      },
      {
         "role": "user",
         "content": "Hi, can you tell me the delivery date for my order?"
      },
      {
         "role": "assistant",
         "content": "Hi there! I can help with that. Can you please provide your order ID?"
      },
      {
         "role": "user",
         "content": "i think it is order_12345"
      }
   ],
   "tools": [
      {
         "type": "function",
         "function": {
            "name": "get_delivery_date",
            "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date of an order, for example when a customer asks 'Where is my package'",
            "parameters": {
               "type": "object",
               "properties": {
                  "order_id": {
                     "type": "string",
                     "description": "The customer's order ID."
                  }
               },
               "required": ["order_id"],
               "additionalProperties": false
            }
         }
      }
   ]
});

var requestOptions = {
   method: 'POST',
   headers: myHeaders,
   body: raw,
   redirect: 'follow'
};

fetch("https://api.quickrouter.ai/v1/chat/completions", requestOptions)
   .then(response => response.text())
   .then(result => console.log(result))
   .catch(error => console.log('error', error));
import http.client
import json

conn = http.client.HTTPSConnection("api.quickrouter.ai")
payload = json.dumps({
   "model": "gpt-4o",
   "messages": [
      {
         "role": "system",
         "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user."
      },
      {
         "role": "user",
         "content": "Hi, can you tell me the delivery date for my order?"
      },
      {
         "role": "assistant",
         "content": "Hi there! I can help with that. Can you please provide your order ID?"
      },
      {
         "role": "user",
         "content": "i think it is order_12345"
      }
   ],
   "tools": [
      {
         "type": "function",
         "function": {
            "name": "get_delivery_date",
            "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date of an order, for example when a customer asks 'Where is my package'",
            "parameters": {
               "type": "object",
               "properties": {
                  "order_id": {
                     "type": "string",
                     "description": "The customer's order ID."
                  }
               },
               "required": ["order_id"],
               "additionalProperties": False
            }
         }
      }
   ]
})
headers = {
   'Authorization': 'Bearer <token>',
   'Content-Type': 'application/json'
}
conn.request("POST", "/v1/chat/completions", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

返回响应

响应参数 🟢 200 OK · application/json
id string
必需
object string
必需
choices array [object]
必需
usage object
必需
示例
{
    "id": "chatcmpl-123",
    "object": "chat.completion",
    "created": 1677652288,
    "model": "gpt-4o",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": null,
                "tool_calls": [
                    {
                        "id": "call_abc123",
                        "type": "function",
                        "function": {
                            "name": "get_delivery_date",
                            "arguments": "{\"order_id\": \"order_12345\"}"
                        }
                    }
                ]
            },
            "finish_reason": "tool_calls"
        }
    ],
    "usage": {
        "prompt_tokens": 120,
        "completion_tokens": 20,
        "total_tokens": 140
    }
}