Cài Đặt
Cài Đặt
npm install @imbrace/sdk# hoặcyarn add @imbrace/sdk# hoặcpnpm add @imbrace/sdkYêu cầu Node.js 18+ (hoặc bất kỳ trình duyệt nào hỗ trợ native fetch và ReadableStream).
pip install imbrace# hoặcuv add imbraceYêu cầu Python 3.9+.
Khởi Tạo Client
import { ImbraceClient } from "@imbrace/sdk"
// Build on Imbrace — Imbrace IS your backend, end-users log in via OTPconst client = new ImbraceClient({ accessToken: "acc_your_token", baseUrl: "https://app-gatewayv2.imbrace.co",})Client có trạng thái — tạo một lần và tái sử dụng trong toàn bộ ứng dụng.
from imbrace import ImbraceClient
# Build on Imbrace — Imbrace IS your backend, end-users log in via OTPwith ImbraceClient(access_token="acc_your_token") as client: ...Python cũng export AsyncImbraceClient (async with ...) cho các stack async như FastAPI.
Context manager tự đóng HTTP connection pool bên dưới.
Để biết khi nào dùng loại credential nào, xem Xác Thực. Để thiết lập credentials từng bước (env vars, dotenv, secrets), xem Hướng Dẫn Cài Đặt.
Kiểm Tra
import { ImbraceClient } from "@imbrace/sdk"console.log("SDK loaded:", typeof ImbraceClient) // "function"from imbrace import ImbraceClientprint("SDK ready:", ImbraceClient)Biến Môi Trường
SDK không tự đọc biến môi trường. Truyền credentials trực tiếp vào constructor và dùng loader (dotenv / cách xử lý env của framework) nếu bạn lưu chúng trong .env.
| Biến | Mục đích |
|---|---|
IMBRACE_API_KEY | API key của bạn (org-level credential) |
IMBRACE_ACCESS_TOKEN | Access token của user (per-session credential) |
IMBRACE_BASE_URL | Override gateway URL (mặc định: https://app-gatewayv2.imbrace.co) |
Org id được mã hoá trong cả API keys và access tokens — bạn không bao giờ cần truyền organizationId/organization_id cho SDK. Xem Xác Thực để biết thêm chi tiết.