API 基础地址:https://api.kanghuiai.com/v1
认证方式:Bearer Token(在请求头添加 Authorization: Bearer <你的API密钥>)
/chat/completions
创建聊天会话完成
GLM-5.3-Flash、qwen3.8:latest、deepseek-v4.1
role 和 content
curl -X POST https://api.kanghuiai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxx你的API密钥xxxxx" \
-d '{
"model": "GLM-5.3-Flash",
"messages": [
{"role": "system", "content": "你是一个有用的AI助手"},
{"role": "user", "content": "你好,请介绍一下自己"}
],
"temperature": 0.7
}'
import openai
client = openai.OpenAI(
base_url="https://api.kanghuiai.com/v1",
api_key="sk-xxxxx你的API密钥xxxxx"
)
response = client.chat.completions.create(
model="GLM-5.3-Flash",
messages=[
{"role": "system", "content": "你是一个有用的AI助手"},
{"role": "user", "content": "你好,请介绍一下自己"}
],
temperature=0.7
)
print(response.choices[0].message.content)
const OpenAI = require('openai');
const client = new OpenAI({
baseURL: 'https://api.kanghuiai.com/v1',
apiKey: 'sk-xxxxx你的API密钥xxxxx'
});
async function chat() {
const response = await client.chat.completions.create({
model: 'GLM-5.3-Flash',
messages: [
{role: 'system', content: '你是一个有用的AI助手'},
{role: 'user', content: '你好,请介绍一下自己'}
],
temperature: 0.7
});
console.log(response.choices[0].message.content);
}
chat();
import com.theokanning.openai.client.OpenAiApi;
import com.theokanning.openai.completion.chat.ChatCompletionRequest;
import com.theokanning.openai.completion.chat.ChatMessage;
import com.theokanning.openai.service.OpenAiService;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
import java.util.Arrays;
public class Example {
public static void main(String[] args) {
String baseUrl = "https://api.kanghuiai.com/v1/";
String apiKey = "sk-xxxxx你的API密钥xxxxx";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(JacksonConverterFactory.create())
.build();
OpenAiApi api = retrofit.create(OpenAiApi.class);
OpenAiService service = new OpenAiService(api, apiKey);
ChatCompletionRequest request = ChatCompletionRequest.builder()
.model("GLM-5.3-Flash")
.messages(Arrays.asList(
new ChatMessage("system", "你是一个有用的AI助手"),
new ChatMessage("user", "你好,请介绍一下自己")
))
.temperature(0.7)
.build();
String response = service.createChatCompletion(request)
.getChoices()
.get(0)
.getMessage()
.getContent();
System.out.println(response);
}
}
package main
import (
"context"
"fmt"
"log"
"github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig("sk-xxxxx你的API密钥xxxxx")
config.BaseURL = "https://api.kanghuiai.com/v1"
client := openai.NewClientWithConfig(config)
resp, err := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: "GLM-5.3-Flash",
Messages: []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
Content: "你是一个有用的AI助手",
},
{
Role: openai.ChatMessageRoleUser,
Content: "你好,请介绍一下自己",
},
},
Temperature: 0.7,
},
)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Choices[0].Message.Content)
}
{
"id": "chatcmpl-1234567890",
"object": "chat.completion",
"created": 1699000000,
"model": "GLM-5.3-Flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!我是 kanghuiAI 助手,很高兴为您服务。我可以帮助您回答问题、完成任务、进行对话等。请问有什么我可以帮到您的吗?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 30,
"completion_tokens": 50,
"total_tokens": 80
}
}
/models
获取可用的模型列表
curl -X GET https://api.kanghuiai.com/v1/models \
-H "Authorization: Bearer sk-xxxxx你的API密钥xxxxx"
| 模型 ID | 提供商 | 描述 | 特点 |
|---|---|---|---|
| 正在加载模型列表… | |||
* 实际可用模型取决于您的账户配置,请通过 GET /models 获取最新列表
| 状态码 | 描述 | 说明 |
|---|---|---|
| 200 | 成功 | 请求成功处理 |
| 400 | 请求错误 | 参数错误或请求格式不正确 |
| 401 | 未授权 | API Key 无效或已过期 |
| 402 | 余额不足 | 账户余额或配额不足 |
| 429 | 请求超限 | 请求频率超限,请稍后重试 |
| 500 | 服务器错误 | 服务端内部错误 |
{
"error": {
"message": "API Key 无效",
"type": "invalid_request_error",
"code": "invalid_api_key"
}
}
API 调用按 Token 数量计费,包含输入 Token 和输出 Token
计算公式:总费用 = (输入 Token × 输入单价) + (输出 Token × 输出单价)
Token 是文本的基本单位,可以理解为词语的片段。通常:
1. 注册并登录账号
2. 访问用户面板 → 创建 API Key
3. 复制保存您的 API Key(仅显示一次)
立即在用户面板删除该 API Key 并创建新的,同时检查账户使用记录
支持!在请求中设置 stream: true 即可使用流式输出
请联系管理员或查看账户设置页面了解充值方式
如有其他问题,请通过以下方式联系我们: