Skip to main content

Introduction to TCB LLM API Supported Protocols

CloudBase AI supports the following protocols: Chat Completions, Responses API, and Anthropic Messages API. Any AI tool that supports custom APIs can be directly integrated.

Prerequisites

  • You have activated a TCB environment and obtained the environment ID cloudBaseEnvID
  • Enable the required model in the AI console
  • Obtain the Base URL and API Key in the AI console
Base URLhttps://<ENV_ID>.api.tcloudbasegateway.com/v1/ai/cloudbase

The most universal large model conversation protocol, OpenAI Compatible, is used by default in the vast majority of AI tools.

Taking tool calling as an example, the complete process requires two API requests:

First Request: Send the user message and available tool definitions

curl https://{{YOUR-ENV-ID}}.api.tcloudbasegateway.com/v1/ai/cloudbase/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {{YOUR-API-KEY}}" \
-d '{
"model": "hy3-preview",
"messages": [
{ "role": "user", "content": "Please check the weather in Beijing for me today." }
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Obtain the weather forecast for a specified city",
"parameters": {
"type": "object",
"properties": {
"location": { "type": "string", "description": "City name" }
},
"required": ["location"]
}
}
}
]
}'

The model returns finish_reason: "tool_calls", indicating that the client needs to execute a tool. After the client calls the tool and obtains the result, it appends the tool's return value to messages and initiates the second request:

Second Request: Carrying the tool call result

curl https://{{YOUR-ENV-ID}}.api.tcloudbasegateway.com/v1/ai/cloudbase/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {{YOUR-API-KEY}}" \
-d '{
"model": "hy3-preview",
"messages": [
{ "role": "user", "content": "Please check the weather in Beijing for me today." },
{
"role": "assistant",
"tool_calls": [{
"id": "call_123",
"type": "function",
"function": { "name": "get_current_weather", "arguments": "{\"location\": \"Beijing\"}" }
}]
},
{
"role": "tool",
"tool_call_id": "call_123",
"content": "{\"temperature\": \"25℃\", \"weather\": \"sunny\"}"
}
]
}'

The model generates the final response based on the result returned by the tool.