@alphid/sdk
v0.3.14
Published
Type-safe Alphid API client generated from OpenAPI spec
Downloads
2,884
Readme
@alphid/sdk
Type-safe Alphid API client generated from the live OpenAPI spec.
Install
npm install @alphid/sdkQuick Start
import { createAlphidClient } from "@alphid/sdk";
const client = createAlphidClient("http://localhost:5050", {
token: process.env.ALPHID_API_KEY,
});
const { data: agents } = await client.GET("/api/agents");
console.log(agents);Streaming
client.stream(...) parses the real SSE event contract exposed by the API.
for await (const event of client.stream(agentId, "Tell me a joke")) {
if (event.event === "chunk") {
process.stdout.write(event.delta);
}
if (event.event === "tool_use") {
console.log("Running tool:", event.tool);
}
if (event.event === "done") {
console.log("Usage:", event.usage);
}
}Supported SSE event names:
chunktool_usetool_resultphasedone
WebSocket
const ws = client.ws(agentId);
ws.on("text_delta", (event) => process.stdout.write(event.content));
ws.on("tool_start", (event) => console.log("Tool:", event.tool));
ws.on("response", (event) => console.log("Done:", event.content));
ws.send("Hello from the SDK");Node and Test Runtimes
In browsers, the SDK uses the global fetch and WebSocket implementations.
In Node or tests, you can inject your own implementations:
import WebSocket from "ws";
import { createAlphidClient } from "@alphid/sdk";
const client = createAlphidClient("http://localhost:5050", {
fetch,
webSocket: WebSocket,
});Type Exports
The root package exports the main client and common types:
import type { paths, components, Schemas, SSEEvent } from "@alphid/sdk";Type-only subpaths are also available:
import type { paths } from "@alphid/sdk/types";
import type { WsServerEvent } from "@alphid/sdk/ws-events";Regenerating Types
The SDK now generates from the live runtime spec instead of tools/openapi-gen output.
npm run generateOptional environment variables:
ALPHID_OPENAPI_URLALPHID_OPENAPI_TOKEN
Checks
npm run check