Skip to main content

Introduction

Kimi is an AI chat service provided by Ace Data Cloud, featuring the Moon’s Dark Side Kimi series large language models. Through the unified API of Ace Data Cloud, you can quickly integrate Kimi using Python to achieve multi-turn conversations, system prompts, streaming output, JSON output mode, and other features.

Prerequisites

  • Have an Ace Data Cloud account and obtain an API Token
  • Python 3.7 or above environment
  • Install the requests library: pip install requests

Basic Usage

The main endpoint for calling the Kimi API is:
POST https://api.acedata.cloud/kimi/chat/completions
This example uses the kimi-k2.5 model.
Available models include: kimi-k2.5, kimi-k2-thinking-turbo, kimi-k2-thinking, kimi-k2-instruct-0905.
Complete Python code example:
import requests

url = "https://api.acedata.cloud/kimi/chat/completions"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}
data = {
    "model": "kimi-k2.5",
    "messages": [
        {
            "role": "user",
            "content": "你好,请介绍一下你自己"
        }
    ],
    "max_tokens": 1024,
    "temperature": 0.7
}

response = requests.post(url, headers=headers, json=data)
result = response.json()
print(result)
Please replace YOUR_API_TOKEN with the actual Token you obtained from the Ace Data Cloud platform.

Response Handling

After a successful call, the API returns data in JSON format. It is recommended to check the HTTP status code:
if response.status_code == 200:
    result = response.json()
    print("Call succeeded:", result)
else:
    print(f"Call failed, status code: {response.status_code}")
    print(response.text)

Advanced Usage

For chat APIs, streaming output is supported to get real-time responses:
import requests

data['stream'] = True
response = requests.post(url, headers=headers, json=data, stream=True)
for line in response.iter_lines():
    if line:
        print(line.decode())

Error Handling

Common error codes:
Status CodeDescription
401Authentication failed, please check API Token
403Insufficient balance or no access permission
429Request rate limit exceeded
500Internal server error

Next Steps