安装并运行你的第一个会话
安装 Dropstone SDK,使用 API 密钥进行无头 API 调用,并运行一个携带你账户记忆的本地代理会话。包括流式输出、结构化输出,以及使用 OpenAI SDK 对接 Dropstone。
两个客户端,两种首次调用。选择与你代码运行环境匹配的那一个;SDK 概述解释了二者的区别。
无头模式:从任何地方发起调用
- 在 仪表盘 的 设置 中,API 密钥 下创建一个 API 密钥。它看起来像
dsk_live_...,并且只显示一次。 - 安装 SDK:
npm install @blankline/dropstone-sdk。 - 将密钥放入环境变量,命名为
DROPSTONE_API_KEY。像对待密码一样对待它:永远不要提交它,也永远不要将其打包进浏览器 bundle。 - 发起调用。客户端会自动读取环境变量。
import { createDropstoneApi } from "@blankline/dropstone-sdk"
const dropstone = createDropstoneApi()
const resp = await dropstone.chat.completions.create({
model: "dropstone-fast",
messages: [{ role: "user", content: "Summarise this changelog entry." }],
})
console.log(resp.choices[0].message.content)
添加 stream: true,同样的调用会返回一个异步的块迭代器,这正是你在 UI 或长回答中需要的:
const stream = await dropstone.chat.completions.create({
model: "dropstone-fast",
stream: true,
messages: [{ role: "user", content: "Count to five." }],
})
for await (const chunk of stream) {
process.stdout.write(chunk.choices?.[0]?.delta?.content ?? "")
}
该端点兼容 OpenAI,因此现有的客户端只需指向 Dropstone 即可使用:
import OpenAI from "openai"
const openai = new OpenAI({
baseURL: "https://api.dropstone.io/api/v1",
apiKey: process.env.DROPSTONE_API_KEY,
})
API 密钥请求按用量从你的信用余额中计费,而非从套餐额度中扣除;余额为空的密钥会被拒绝,并附带充值链接。参见 将 API 与你的套餐配合使用。
本地模式:在你的进程中运行代理
本地客户端会启动一个 dropstone serve 进程,向你提供一个指向它的类型化客户端,并在你完成后关闭它。由于它以你的账户身份运行,会话会携带你的记忆。
- 安装 Dropstone CLI 并使用
dropstone login登录。SDK 会读取相同的登录状态。 - 创建一个会话,然后向它发送提示。
import { createDropstone } from "@blankline/dropstone-sdk"
const { client, server } = await createDropstone()
const session = await client.session.create({
body: { agent: "build", model: { providerID: "dropstone", modelID: "dropstone-pro" } },
})
const reply = await client.session.prompt({
path: { id: session.data.id },
body: { parts: [{ type: "text", text: "Hello, who are you?" }] },
})
console.log(reply.data)
await server.close()
如果服务器已经在运行,可以跳过启动过程:
import { createDropstoneClient } from "@blankline/dropstone-sdk"
const client = createDropstoneClient({ baseUrl: "http://127.0.0.1:4096" })
提示
- 固定版本范围。 SDK 发布节奏很快,因此请依赖你测试过的版本范围,而不是最新的标签。
- 新代码使用 v2。
@blankline/dropstone-sdk/v2是新端点落地的界面;v1 保留给现有集成。 - 不要把流水线的学习内容混入你自己的记忆。 无头调用不附带任何记忆,本地会话使用你登录的账户。如果某个集成需要自己的记忆,请给它一个独立的账户。参见 每个界面共享一份记忆。
限制
- 本地客户端需要 CLI 在同一台机器上;没有 CLI 的主机应使用无头客户端。
- 无头端点是聊天补全。代理循环、文件操作和工作区工具都在本地客户端上。
Related articles
- Dropstone SDKA typed TypeScript and JavaScript client for the Dropstone agent, with two entry points: one for headless API calls from CI or a serverless function, one that runs the agent locally with the same account memory as the CLI and Chat.
- Using the API with your planCall Dropstone over HTTP with an API key. The endpoint is OpenAI-compatible, billed pay-per-use from your credit balance, and works from any language. Keys, errors, rate limits, and what the API does not carry.
- One memory across every surfaceThe account memory that follows you across Dropstone Chat, the CLI, and the SDK, what shares it and what does not, and how to keep an integration's learning out of your own memory.
- Install the CLIInstall the Dropstone CLI on macOS, Linux, or Windows with one command, sign in, and check it works. Upgrading and uninstalling.
- How to get supportHow to reach Dropstone support, what to include so we can help quickly, and the right address for billing, privacy, security, and enterprise questions.
Ctrl+I