Quickstart — Automate with an API key
Prerequisites
1. Create a key
2. Exchange the key for a token
TOKEN=$(curl -s -X POST https://back.kai-studio.ai/core/api-key/token \
-H "Content-Type: application/json" \
-d '{"api_key": "'"$KAI_ORG_KEY"'"}' | jq -r '.response.access_token')import os, httpx
resp = httpx.post(
"https://back.kai-studio.ai/core/api-key/token",
json={"api_key": os.environ["KAI_ORG_KEY"]},
)
resp.raise_for_status()
token = resp.json()["response"]["access_token"]const resp = await fetch("https://back.kai-studio.ai/core/api-key/token", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ api_key: process.env.KAI_ORG_KEY }),
});
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
const token = (await resp.json()).response.access_token;3. First call
curl -s -X POST https://back.kai-studio.ai/studio/organization/my-access \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{}' | jq '.response'resp = httpx.post(
"https://back.kai-studio.ai/studio/organization/my-access",
headers={"Authorization": f"Bearer {token}"},
json={},
)
print(resp.json()["response"])const access = await fetch(
"https://back.kai-studio.ai/studio/organization/my-access",
{
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
},
).then((r) => r.json());
console.log(access.response);4. Reuse the token
Next steps
Last updated