5.2. Xác thực
TwinExpert API sử dụng API key để xác thực requests
Bảo mật API Key
API key của bạn có quyền truy cập vào dữ liệu. Hãy giữ bí mật và không chia sẻ trong code phía client.
Cách sử dụng API Key
Thêm API key vào header Authorization của mọi request:
Authorization Header
Authorization: Bearer YOUR_API_KEY
Hoặc sử dụng X-API-Key header
X-API-Key: YOUR_API_KEY
Post
/api/v1/auth/api-keys
<>Ví dụ code
Tạo API key mới bằng JWT token
// Tạo API key mới
const response = await fetch('https://api.twinexpert.com/api/v1/auth/api-keys', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_JWT_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'My App',
scope: 'full_access'
})
});
const data = await response.json();
console.log('API Key:', data.data.key);
Phạm vi quyền (Scopes)
read_only Chỉ Đọc
Xem danh sách TwinsĐọc thông tin cuộc trò chuyênXem lịch sử tin nhắn200 requests/giờ
full_accessChỉ Đọc
Tất cả quyền của Read_onlyTạo cuộc trò chuyện mớiGửi tin nhắn500 requests/giờ
Last updated