@onioneko/kiki-llm-openai
v0.1.3
Published
OpenAI-compatible LLM provider middleware for @onioneko/kiki-core
Maintainers
Readme
@onioneko/kiki-llm-openai
Kiki · Middleware framework for LLM agents
npm install @onioneko/kiki-llm-openaiOpenAI-compatible LLM provider as middleware. Calls the Chat Completions
API and pushes the assistant response onto ctx.messages, then calls
next() to allow response-processing middleware downstream.
Compatible with any OpenAI-compatible provider (OpenAI, Azure OpenAI,
Ollama, Together, vLLM, etc.) via the baseURL config.
Usage
import { compose } from "@onioneko/kiki-core";
import { createOpenAIMiddleware } from "@onioneko/kiki-llm-openai";
const run = compose([
// ... other middleware ...
createOpenAIMiddleware({ model: "gpt-4.1" }),
]);
await run({ messages: [{ role: "user", content: "hello" }] });With a compatible provider
createOpenAIMiddleware({
baseURL: "http://localhost:11434/v1", // Ollama
model: "llama3",
});Configuration
model is required. Other fields are optional with sensible defaults.
| Option | Env var | Default | Description |
|------------|------------------|-----------|------------------------------------------|
| model | — | — | Model identifier (required) |
| apiKey | OPENAI_API_KEY | — | API key (required unless client injected) |
| maxTokens| — | 16384 | Maximum tokens in response |
| baseURL | OPENAI_BASE_URL| — | Base URL for compatible providers |
| client | — | — | Injected OpenAI client (for testing) |
Config precedence: explicit config > default.
Behavior
- Non-terminal — calls
next()after pushing the response, allowing response-processing middleware to be composed after the LLM. - Multi-modal — handles text and image content blocks (images sent as data URIs).
- System prompt —
ctx.systemis prepended as arole: "system"message. - OpenAI-compatible — works with any provider that supports the Chat Completions API.
Exports
createOpenAIMiddleware(config)— factory function returning aMiddleware.OpenAIConfig— configuration type.- Re-exports from
@onioneko/kiki-types:Message,ConversationContext,ContentBlock,TextBlock,ImageBlock.
