@kenkaiiii/gg-ai
v4.2.6
Published
Unified LLM streaming API for Anthropic and OpenAI
Readme
@kenkaiiii/gg-ai
One function. Flat options. Switch providers by changing a string. No adapters, no plugins, no wrapper classes.
Part of the GG Framework monorepo.
Install
npm i @kenkaiiii/gg-aiHow it works
Call stream() with a provider, model, and messages. That's the entire API.
for awaitgives you streaming events (text_delta,thinking_delta,toolcall_done, etc.)awaitgives you the final response (message,stopReason,usage)
Same function, same call. Dual-nature StreamResult — async iterable and thenable.
Tool parameters are Zod schemas. Converted to JSON Schema at the provider boundary automatically.
Providers
| Provider | Models | Notes |
|---|---|---|
| anthropic | Claude Opus 4.6, Sonnet 4.6, Haiku 4.5 | Extended thinking, prompt caching, server-side compaction |
| openai | GPT-4.1, o3, o4-mini | Supports OAuth (codex endpoint) and API keys |
| glm | GLM-5, GLM-4.7 | Z.AI platform, OpenAI-compatible |
| moonshot | Kimi K2.5 | Moonshot platform, OpenAI-compatible |
Stream events
| Event | Description |
|---|---|
| text_delta | Incremental text output |
| thinking_delta | Extended thinking output (Anthropic) |
| toolcall_delta | Streaming tool call arguments |
| toolcall_done | Completed tool call with parsed args |
| server_toolcall | Server-side tool invocation |
| server_toolresult | Server-side tool result |
| done | Stream finished, includes stop reason |
| error | Error occurred |
Options
| Option | Type | Description |
|---|---|---|
| provider | "anthropic" \| "openai" \| "glm" \| "moonshot" | Required |
| model | string | Required |
| messages | Message[] | Required |
| tools | Tool[] | Tool definitions with Zod schemas |
| toolChoice | "auto" \| "none" \| "required" \| { name } | Tool selection strategy |
| serverTools | ServerToolDefinition[] | Server-side tool definitions |
| maxTokens | number | Max output tokens |
| temperature | number | Sampling temperature |
| topP | number | Nucleus sampling |
| stop | string[] | Stop sequences |
| thinking | "low" \| "medium" \| "high" \| "max" | Extended thinking (Anthropic) |
| apiKey | string | Provider API key |
| baseUrl | string | Custom endpoint |
| signal | AbortSignal | Cancellation |
| cacheRetention | "none" \| "short" \| "long" | Prompt cache preference |
| compaction | boolean | Server-side compaction (Anthropic only) |
License
MIT
