Endpoints API Toolkit
Setup
Install dependencies:
CODEBLOCK0
Configure credentials by creating a .env file in the project root:
CODEBLOCK1
Prerequisites: An Endpoints account with an API key. Generate your API key from the API Keys page.
Quick Start
| User says | Function to call |
|---|
| "List my endpoints" | INLINECODE1 |
| "Show endpoint details for /job-tracker/january" |
getEndpoint('/job-tracker/january') |
| "Scan this document" |
scanFile('/path/to/file.pdf', 'job tracker') |
| "Scan this text" |
scanText('Meeting notes...', 'meeting tracker') |
| "Create an endpoint for receipts" |
createEndpoint('/receipts/2026') |
| "Delete the old endpoint" |
deleteEndpoint('/category/slug') |
| "Remove that item" |
deleteItem('abc12345') |
| "Get the file URL" |
getFileUrl('userid/path/file.pdf') |
| "Check my usage" |
getStats() |
Execute functions by importing from scripts/src/index.ts:
CODEBLOCK2
Or run directly with tsx:
CODEBLOCK3
Workflow Pattern
Every analysis follows three phases:
1. Analyze
Run API functions. Each call hits the Endpoints API and returns structured data.
2. Auto-Save
All results automatically save as JSON files to
results/{category}/. File naming patterns:
- - Named results: INLINECODE12
- Auto-generated: INLINECODE13
3. Summarize
After analysis, read the saved JSON files and create a markdown summary in
results/summaries/ with data tables, insights, and extracted entities.
High-Level Functions
| Function | Purpose | What it returns |
|---|
| INLINECODE15 | Get all endpoints by category | Tree structure with categories and endpoints |
| INLINECODE16 |
Get endpoint details | Full metadata (old + new items) |
|
scanText(text, prompt) | Scan text with AI | Extracted entities and endpoint path |
|
scanFile(filePath, prompt) | Scan file with AI | Extracted entities and endpoint path |
|
getStats() | Get usage statistics | Parses used, limits, storage |
Individual API Functions
For granular control, import specific functions. See references/api-reference.md for the complete list with parameters, types, and examples.
Endpoint Functions
| Function | Purpose |
|---|
| INLINECODE20 | List all endpoints organized by category |
| INLINECODE21 |
Get full endpoint details with metadata |
|
createEndpoint(path) | Create a new empty endpoint |
|
deleteEndpoint(path) | Delete endpoint and all associated files |
Scanning Functions
| Function | Purpose |
|---|
| INLINECODE24 | Scan text content with AI extraction |
| INLINECODE25 |
Scan file (PDF, images, docs) with AI |
Item Functions
| Function | Purpose |
|---|
| INLINECODE26 | Delete a single item by its 8-char ID |
File Functions
| Function | Purpose |
|---|
| INLINECODE27 | Get presigned S3 URL for a file |
Billing Functions
| Function | Purpose |
|---|
| INLINECODE28 | Get usage stats (parses, storage, tier) |
Data Structures
Living JSON Pattern
Endpoints use the Living JSON pattern for document history:
CODEBLOCK4
Metadata Item
Each item has:
- - 8-character ID - Unique identifier (e.g.,
abc12345) - summary - AI-generated description
- entities - Extracted entities (people, companies, dates)
- filePath - S3 URL if file was uploaded
- fileType - MIME type
- originalText - Source text
Error Handling
| Status | Meaning |
|---|
| 401 | Invalid or missing API key |
| 404 |
Endpoint or item not found |
| 409 | Endpoint already exists |
| 429 | Usage limit exceeded |
Examples
List and Inspect
CODEBLOCK5
Scan Documents
CODEBLOCK6
Check Usage
CODEBLOCK7
Endpoints API 工具包
环境设置
安装依赖:
bash
cd scripts && npm install
在项目根目录创建 .env 文件配置凭证:
ENDPOINTSAPIURL=https://endpoints.work
ENDPOINTSAPIKEY=epyourapikeyhere
前置条件:拥有 API 密钥的 Endpoints 账户。从 API 密钥页面 生成您的 API 密钥。
快速入门
| 用户指令 | 调用函数 |
|---|
| 列出我的端点 | listEndpoints() |
| 显示 /job-tracker/january 的端点详情 |
getEndpoint(/job-tracker/january) |
| 扫描此文档 | scanFile(/path/to/file.pdf, job tracker) |
| 扫描此文本 | scanText(会议记录..., meeting tracker) |
| 为收据创建端点 | createEndpoint(/receipts/2026) |
| 删除旧端点 | deleteEndpoint(/category/slug) |
| 移除该项目 | deleteItem(abc12345) |
| 获取文件 URL | getFileUrl(userid/path/file.pdf) |
| 查看我的使用情况 | getStats() |
通过从 scripts/src/index.ts 导入来执行函数:
typescript
import { listEndpoints, scanText, getStats } from ./scripts/src/index.js;
const categories = await listEndpoints();
const result = await scanText(与 John 讨论第一季度目标的会议, meeting tracker);
const stats = await getStats();
或直接使用 tsx 运行:
bash
npx tsx scripts/src/index.ts
工作流程模式
每次分析遵循三个阶段:
1. 分析
运行 API 函数。每次调用都会访问 Endpoints API 并返回结构化数据。
2. 自动保存
所有结果自动保存为 JSON 文件到 results/{category}/ 目录。文件命名规则:
- - 命名结果:{清理后的名称}.json
- 自动生成:YYYYMMDDHHMMSS_{操作}.json
3. 总结
分析完成后,读取已保存的 JSON 文件,在 results/summaries/ 中创建包含数据表格、洞察和提取实体的 Markdown 总结。
高级函数
| 函数 | 用途 | 返回值 |
|---|
| listEndpoints() | 按类别获取所有端点 | 包含类别和端点的树形结构 |
| getEndpoint(path) |
获取端点详情 | 完整元数据(旧项目 + 新项目) |
| scanText(text, prompt) | 使用 AI 扫描文本 | 提取的实体和端点路径 |
| scanFile(filePath, prompt) | 使用 AI 扫描文件 | 提取的实体和端点路径 |
| getStats() | 获取使用统计 | 解析次数、限制、存储空间 |
独立 API 函数
如需精细控制,可导入特定函数。完整列表(含参数、类型和示例)请参见 references/api-reference.md。
端点函数
| 函数 | 用途 |
|---|
| listEndpoints() | 列出按类别组织的所有端点 |
| getEndpoint(path) |
获取包含元数据的完整端点详情 |
| createEndpoint(path) | 创建新的空端点 |
| deleteEndpoint(path) | 删除端点及其所有关联文件 |
扫描函数
| 函数 | 用途 |
|---|
| scanText(text, prompt) | 使用 AI 提取扫描文本内容 |
| scanFile(filePath, prompt) |
使用 AI 扫描文件(PDF、图片、文档) |
项目函数
| 函数 | 用途 |
|---|
| deleteItem(itemId) | 通过 8 字符 ID 删除单个项目 |
文件函数
| 函数 | 用途 |
|---|
| getFileUrl(key) | 获取文件的预签名 S3 URL |
计费函数
| 函数 | 用途 |
|---|
| getStats() | 获取使用统计(解析次数、存储空间、套餐等级) |
数据结构
实时 JSON 模式
端点使用实时 JSON 模式记录文档历史:
typescript
{
endpoint: { path, category, slug },
metadata: {
oldMetadata: { ... }, // 历史项目
newMetadata: { ... } // 近期项目
}
}
元数据项目
每个项目包含:
- - 8 字符 ID - 唯一标识符(例如 abc12345)
- summary - AI 生成的描述
- entities - 提取的实体(人物、公司、日期)
- filePath - 上传文件的 S3 URL
- fileType - MIME 类型
- originalText - 源文本
错误处理
端点或项目未找到 |
| 409 | 端点已存在 |
| 429 | 超出使用限制 |
示例
列出和检查
typescript
// 获取所有端点
const { categories } = await listEndpoints();
console.log(找到 ${categories.length} 个类别);
// 检查特定端点
const details = await getEndpoint(/job-tracker/january);
console.log(项目总数:${details.totalItems});
扫描文档
typescript
// 扫描文本内容
const result = await scanText(
来自 Acme Corp 的 John Smith 关于第一季度合同续签的邮件,
business contacts
);
console.log(创建的端点:${result.endpoint.path});
// 扫描 PDF 文件
const fileResult = await scanFile(./invoice.pdf, invoice tracker);
console.log(提取了 ${fileResult.entriesAdded} 个项目);
查看使用情况
typescript
const stats = await getStats();
console.log(解析次数:${stats.parsesUsed}/${stats.parsesLimit});
console.log(存储空间:${stats.storageUsed} 字节);