Good afternoon, I can’t connect kling api in my project. I have accessKey ID and AccessKey Secret, which of these should I use to authenticate kling api? I tried to connect both in Bearer (accessKey ID/AccessKey Secret) format, it didn’t help. I’m getting 401 code:1000 errors. Please help me
Hi, I can help.
So you need to generate a JWT token which needs the access key and the secret key.
Are you self hosting ore on the cloud?
There seems to be general confusion around JWT regarding all the annoyingly similar terminology used for different things (access-key, secret-key, access-key-id, access-key-secret, private-key, public-key, client-secret, access-token, etc.)
The n8n JWT node provides a way to construct the (JSON) content of a JWT, and sign it using a Passphrase or a “PEM Key” (Private Key + Public Key).
The Kling docs show the JWT payload (in Python code) as:
{
"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 minus 5s
}
So, based on that:
- The “AccessKey Secret” you have is probably what n8n wants in the JWT credential as the value of the
Secret
field, when the selectedKey Type
isPassphrase
. - The “AccessKey ID” should probably be added into the JWT node itself as the
Issuer
Payload Claim. - Also add an “Expires In” Payload Claim
- Also add a “Not Before” Payload Claim