Skip to main content

Obtain ApiKey

What is ApiKey

ApiKeyis similar toAccessToken, and is a security Token` used for user authentication.

Differences between ApiKeyandAccessToken`:

  1. ApiKey belongs to the B-end identity, which is the developer identity, with administrator-level permissions, while AccessToken obtained via login belongs to the C-end identity, with ordinary user-level permissions.
  2. ApiKey is typically used on the server-side, while AccessToken is typically used on the client-side.
  3. ApiKey is typically long-term valid, while AccessToken is usually short-term valid and requires regular refreshing with RefreshToken.

How to obtain ApiKey?

  1. Go to CloudBase and select the corresponding environment
  2. Go to Environment Configuration -> ApiKey Management Page -> Create ApiKey to obtain ApiKey

How to use ApiKey?

Similar to AccessToken, when making API calls, include ApiKey in the request header.

Authorization: Bearer <ApiKey>

If using the openai SDK to call large model APIs, you can pass ApiKey when initializing the OpenAI instance.

import OpenAI from "openai";

const client = new OpenAI({
apiKey: `your-apui-key`,
});