Skip to main content
GET
/
v1
/
users
/
me
/
balance
Check Balance
curl --request GET \
  --url https://api.moonshot.ai/v1/users/me/balance \
  --header 'Authorization: Bearer <token>'
import requests

url = "https://api.moonshot.ai/v1/users/me/balance"

headers = {"Authorization": "Bearer <token>"}

response = requests.get(url, headers=headers)

print(response.text)
const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

fetch('https://api.moonshot.ai/v1/users/me/balance', 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://api.moonshot.ai/v1/users/me/balance",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);

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

curl_close($curl);

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

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

func main() {

url := "https://api.moonshot.ai/v1/users/me/balance"

req, _ := http.NewRequest("GET", url, nil)

req.Header.Add("Authorization", "Bearer <token>")

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

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

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.get("https://api.moonshot.ai/v1/users/me/balance")
.header("Authorization", "Bearer <token>")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.moonshot.ai/v1/users/me/balance")

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

request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
{
  "code": 123,
  "data": {
    "available_balance": 49.58894,
    "voucher_balance": 46.58893,
    "cash_balance": 3.00001
  },
  "scode": "0x0",
  "status": true
}
{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}
{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}
Check your available, voucher, and cash balances on the Kimi Open Platform. When the available balance is less than or equal to 0, you cannot call the inference API.
import os
import requests

api_key = os.environ.get("MOONSHOT_API_KEY")
url = "https://api.moonshot.ai/v1/users/me/balance"

response = requests.get(
    url,
    headers={"Authorization": f"Bearer {api_key}"},
)
print(response.json())
curl https://api.moonshot.ai/v1/users/me/balance \
  -H "Authorization: Bearer $MOONSHOT_API_KEY"
const apiKey = process.env.MOONSHOT_API_KEY;

async function main() {
    const response = await fetch("https://api.moonshot.ai/v1/users/me/balance", {
        method: "GET",
        headers: {
            Authorization: `Bearer ${apiKey}`,
        },
    });
    const data = await response.json();
    console.log(data);
}

main();
FieldTypeDescription
codeintegerResponse code. 0 indicates success.
dataobjectBalance data object
data.available_balancenumberThe available balance (unit: USD), including cash balance and voucher balance. When it is less than or equal to 0, the user cannot call the inference API
data.voucher_balancenumberThe voucher balance (unit: USD), which cannot be negative
data.cash_balancenumberThe cash balance (unit: USD), which can be negative, indicating that the user owes money. When it is negative, available_balance is equal to the value of voucher_balance
scodestringStatus code
statusbooleanRequest status
Response Example
{
    "code": 0,
    "data": {
        "available_balance": 49.58894,
        "voucher_balance": 46.58893,
        "cash_balance": 3.00001
    },
    "scode": "0x0",
    "status": true
}
When available_balance is less than or equal to 0, API requests will return an exceeded_current_quota_error error. Please recharge your account or check your voucher validity.
API Keys from platform.kimi.ai and platform.kimi.com are completely independent. Using a Key from one platform on the other will result in a 401 error. Ensure your endpoint matches the platform where the Key was created.

Authorizations

Authorization
string
header
required

The Authorization header expects a Bearer token. Use an MOONSHOT_API_KEY as the token. This is a server-side secret key. Generate one on the API keys page in your dashboard.

Response

Balance information

code
integer
required

Response code. 0 indicates success.

data
object
required
scode
string
required

Status code

Example:

"0x0"

status
boolean
required

Request status

Example:

true