Obtain ApiKey
What is ApiKey
ApiKeyis similar to
AccessToken, and is a security
Token` used for user authentication.
Differences between
ApiKeyand
AccessToken`:
ApiKey
belongs to the B-end identity, which is the developer identity, with administrator-level permissions, whileAccessToken
obtained via login belongs to the C-end identity, with ordinary user-level permissions.ApiKey
is typically used on the server-side, whileAccessToken
is typically used on the client-side.ApiKey
is typically long-term valid, whileAccessToken
is usually short-term valid and requires regular refreshing withRefreshToken
.
How to obtain ApiKey?
- Go to CloudBase and select the corresponding environment
- Go to
Environment Configuration
->ApiKey Management Page
->Create ApiKey
to obtainApiKey
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`,
});