The Kling 3.0 series models API is now fully available
Learn More

General Information


API Domain

https://api-singapore.klingai.com
💡

Notice: The API endpoint for the new system has been updated from https://api.klingai.com to https://api-singapore.klingai.com. This API is suitable for users whose servers are located outside of China.

API Authentication

  • Step-1:Obtain AccessKey + SecretKey
  • Step-2:Every time you request the API, you need to generate an API Token according to the fixed encryption method; put Authorization = Bearer <API Token> in the Request Header
    • Encryption Method:Follow JWT(Json Web Token, RFC 7519)standard
    • JWT consists of three parts:Header、Payload、Signature
import time
import jwt

ak = "" # fill access key
sk = "" # fill secret key

def encode_jwt_token(ak, sk):
    headers = {
        "alg": "HS256",
        "typ": "JWT"
    }
    payload = {
        "iss": ak,
        "exp": int(time.time()) + 1800, # The valid time, in this example, represents the current time+1800s(30min)
        "nbf": int(time.time()) - 5 # The time when it starts to take effect, in this example, represents the current time -5s
    }
    token = jwt.encode(payload, sk, headers=headers)
    return token

authorization = encode_jwt_token(ak, sk)
print(authorization) # Printing the generated API_TOKEN
  • Step-3: Use the API Token generated in Step 2 to assemble the Authorization and include it in the Request Header.
    • Assembly format: Authorization = “Bearer XXX”, where XXX is the API Token generated in Step 2.
    • Note: There should be a space between Bearer and XXX.

Error Code

HTTP Status CodeService CodeDefinition of Service CodeExplaination of Service CodeSuggested Solutions
2000Request successful--
4011000Authentication failedAuthentication failedCheck if the Authorization is correct
4011001Authentication failedAuthorization is emptyFill in the correct Authorization in the Request Header
4011002Authentication failedAuthorization is invalidFill in the correct Authorization in the Request Header
4011003Authentication failedAuthorization is not yet validCheck the start effective time of the token, wait for it to take effect or reissue
4011004Authentication failedAuthorization has expiredCheck the validity period of the token and reissue it
4291100Account exceptionAccount exceptionVerifying account configuration information
4291101Account exceptionAccount in arrears (postpaid scenario)Recharge the account to ensure sufficient balance
4291102Account exceptionResource pack depleted or expired (prepaid scenario)Purchase additional resource packages, or activate the post-payment service (if available)
4031103Account exceptionUnauthorized access to requested resource, such as API/modelVerifying account permissions
4001200Invalid request parametersInvalid request parametersCheck whether the request parameters are correct
4001201Invalid request parametersInvalid parameters, such as incorrect key or illegal valueRefer to the specific information in the message field of the returned body and modify the request parameters
4041202Invalid request parametersThe requested method is invalidReview the API documentation and use the correct request method
4041203Invalid request parametersThe requested resource does not exist, such as the modelRefer to the specific information in the message field of the returned body and modify the request parameters
4001300Trigger strategyTrigger strategy of the platformCheck if any platform policies have been triggered
4001301Trigger strategyTrigger the content security policy of the platformCheck the input content, modify it, and resend the request
4291302Trigger strategyThe API request is too fast, exceeding the platform’s rate limitReduce the request frequency, try again later, or contact customer service to increase the limit
4291303Trigger strategyConcurrency or QPS exceeds the prepaid resource package limitReduce the request frequency, try again later, or contact customer service to increase the limit
4291304Trigger strategyTrigger the platform’s IP whitelisting policyContact customer service
5005000Internal errorServer internal errorTry again later, or contact customer service
5035001Internal errorServer temporarily unavailable, usually due to maintenanceTry again later, or contact customer service
5045002Internal errorServer internal timeout, usually due to a backlogTry again later, or contact customer service
API Domain
API Authentication
Error Code