安裝並執行你的第一個工作階段
安裝 Dropstone SDK、使用 API 金鑰進行無頭 API 呼叫,並執行一個攜帶你帳戶記憶的本地代理程式工作階段。包含串流、結構化輸出,以及使用 OpenAI SDK 搭配 Dropstone。
兩個用戶端,兩個首次呼叫。選擇符合你程式碼執行環境的那一個;SDK 總覽 說明了兩者的差異。
無頭:從任何地方進行呼叫
- 在 儀表板 的 設定 中,於 API 金鑰 底下建立一個 API 金鑰。它看起來像
dsk_live_...,而且只會顯示一次。 - 安裝 SDK:
npm install @blankline/dropstone-sdk。 - 將金鑰放入環境變數,命名為
DROPSTONE_API_KEY。請像對待密碼一樣對待它:絕不提交,也絕不將它放入瀏覽器套件中。 - 呼叫它。用戶端會自行讀取環境變數。
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