API 集成
Hindsight Cloud 的 Connect 页面提供了将 Hindsight API 集成到你应用中所需的一切。
访问 Connect 页面
- 登录 Hindsight Cloud
- 点击顶部导航栏中的 Connect 按钮
API 端点
你的 API 端点显示在 Connect 页面顶部。这是所有 API 请求的基础 URL:
https://api.hindsight.vectorize.io
点击 Copy 按钮即可将端点复制到剪贴板。
管理 API 密钥
查看你的 API 密钥
Connect 页面显示你最近一次创建且仍处于活动状态的 API 密钥:
- 密钥前缀(Key Prefix):密钥的前几位字符(用于识别)
- 状态(Status):Active(活动)或 Revoked(已撤销)
- 创建时间(Created):密钥创建的时间
创建新的 API 密钥
- 点击 Create API Key
- 输入一个描述性名称(例如 "Production Server"、"Development")
- 选择过期时间:
- Never - 密钥永不过期
- 30 days
- 90 days
- 1 year
- Custom - 输入具体天数
- 点击 Create
重要
你的 API 密钥仅在创建后显示一次。请立即复制并安全存储。如果丢失,你需要重新创建一个新密钥。
管理所有 API 密钥
点击 Manage API Keys 进入完整的 API 密钥 页面,在那里你可以:
- 查看所有活动和已撤销的密钥
- 按状态筛选
- 撤销不再需要的密钥
快速入门代码示例
Connect 页面提供了多种语言的即用型代码示例。每个示例都包含你的实际 API 密钥(如果可用),方便复制粘贴。
安装
- Python
- TypeScript
pip install hindsight-client
npm install @vectorize-io/hindsight-client
基本用法
- Python
- TypeScript
- cURL
from hindsight_client import Hindsight
client = Hindsight(
base_url="https://api.hindsight.vectorize.io",
api_key="your-api-key"
)
# Store a memory
client.retain(
bank_id="my-bank",
content="The user prefers dark mode."
)
# Retrieve memories
result = client.recall(
bank_id="my-bank",
query="What are the user's preferences?"
)
for memory in result.results:
print(memory.text)
import { HindsightClient } from '@vectorize-io/hindsight-client';
const client = new HindsightClient({
baseUrl: 'https://api.hindsight.vectorize.io',
apiKey: 'your-api-key'
});
// Store a memory
await client.retain(
'my-bank',
'The user prefers dark mode.'
);
// Retrieve memories
const result = await client.recall(
'my-bank',
"What are the user's preferences?"
);
result.results.forEach(memory => {
console.log(memory.text);
});
# Store a memory
curl -X POST https://api.hindsight.vectorize.io/v1/default/banks/my-bank/memories \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{"items": [{"content": "The user prefers dark mode."}]}'
# Retrieve memories
curl -X POST https://api.hindsight.vectorize.io/v1/default/banks/my-bank/memories/recall \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{"query": "What are the user'\''s preferences?"}'
认证
所有 API 请求都需要通过 API 密钥进行认证。将其包含在 Authorization 标头中:
Authorization: Bearer your-api-key
或使用 SDK 时:
- Python
- TypeScript
client = Hindsight(api_key="your-api-key")
const client = new HindsightClient({ apiKey: 'your-api-key' });
错误处理
API 返回标准 HTTP 状态码:
| 状态码 | 说明 |
|---|---|
| 200 | 成功 |
| 400 | 请求错误 - 请检查请求参数 |
| 401 | 未授权 - API 密钥无效或已过期 |
| 402 | 需付款 - 额度不足 |
| 403 | 禁止访问 - 权限不足 |
| 404 | 未找到 - 资源不存在 |
| 500 | 服务器错误 - 请联系支持 |
后续步骤
- 查看详细的 API 密钥管理
- 了解 记忆操作
- 查看 Python SDK 指南
- 查看 TypeScript SDK 指南