forked from coze-dev/coze-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth-pat.ts
26 lines (19 loc) · 833 Bytes
/
auth-pat.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
* How to use personal access token to init Coze client.
*/
import { CozeAPI } from '@coze/api';
import config from '../config/config.default.js';
// 'en' for https://api.coze.com, 'cn' for https://api.coze.cn
const key = (process.env.COZE_ENV || 'en') as keyof typeof config;
// Retrieve the API key (Personal Access Token) from the configuration based on the current environment
const apiKey = config[key].auth.pat.COZE_API_KEY;
// The default base URL is https://api.coze.com
const baseURL = config[key].COZE_BASE_URL;
// Initialize a new Coze API client using the base URL and API key (Personal Access Token)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const client = new CozeAPI({
baseURL,
token: apiKey,
});
// Example of how to use the client (commented out)
// e.g. client.chat.stream(...);