@byokapi/client
The client package is the main SDK for consumer apps. It handles bridge connection, grant management, and provides AI SDK v6 compatible model providers.
Installation
npm install @byokapi/clientByokClient
The main entry point. Creates and manages the connection to the bridge.
import { ByokClient } from "@byokapi/client"
const client = new ByokClient({
bridgeUrl: "http://localhost:8881/bridge",
appName: "My App",
})Configuration
| Option | Type | Description |
|---|---|---|
bridgeUrl | string | URL to the bridge's iframe endpoint |
appName | string | Display name shown in the consent popup |
Methods
connect(): Promise<void>
Creates a hidden iframe, establishes the RPC channel, and performs the handshake. Automatically restores existing grants.
await client.connect()requestGrant(params): Promise<GrantRequestResult>
Opens a consent popup requesting capabilities from the user.
const result = await client.requestGrant({
capabilities: ["language", "image"],
})
if (result.type === "approved") {
// Access granted
}getProvider(): (modelId: string) => TransportLanguageModel
Returns a provider function compatible with AI SDK v6.
import { generateText } from "ai"
const provider = client.getProvider()
const { text } = await generateText({
model: provider("gpt-4o"),
prompt: "Hello!",
})revokeGrant(grantId: string): Promise<void>
Revokes an active grant.
getGrantState(): GrantState
Returns the current grant state. This is a MobX observable — use it in observer components for reactive updates.
dispose(): void
Cleans up the iframe, RPC channel, and all state. Call this when unmounting your app.
Observable state
ByokClient uses MobX makeAutoObservable, so all properties are observable:
grantState— current grant state (none,pending,granted,denied,revoked,expired)ready— whether the bridge connection is establishedgrantSet— the full grant request result
Auto-generated API docs
See the full API reference for all exported types and methods.