@agentic-kit/openai 1.0.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,14 +12,132 @@
12
12
  <a href="https://www.npmjs.com/package/@agentic-kit/openai"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/agentic-kit?filename=packages%2Fopenai%2Fpackage.json"/></a>
13
13
  </p>
14
14
 
15
- OpenAI (and OpenAI-compatible) adapter for agentic-kit. Works with GPT models, LM Studio, vLLM, Together AI, and any OpenAI-compatible endpoint.
15
+ OpenAI and OpenAI-compatible adapter for `agentic-kit`. Works with GPT models,
16
+ LM Studio, vLLM, Together AI, Groq, Mistral, and any other endpoint speaking
17
+ the chat-completions wire format. Compatibility quirks (token field naming,
18
+ reasoning effort, tool-call id encoding) are toggleable per-model via the
19
+ `compat` block.
16
20
 
17
21
  ## Installation
18
22
 
19
23
  ```bash
20
- npm install @agentic-kit/openai
24
+ npm install @agentic-kit/openai agentic-kit
21
25
  ```
22
26
 
27
+ ## Usage
28
+
29
+ ### Direct adapter
30
+
31
+ ```ts
32
+ import { OpenAIAdapter } from '@agentic-kit/openai';
33
+
34
+ const adapter = new OpenAIAdapter({
35
+ apiKey: process.env.OPENAI_API_KEY!,
36
+ baseUrl: 'https://api.openai.com/v1',
37
+ });
38
+ const model = adapter.createModel('gpt-5.4-mini');
39
+
40
+ const result = adapter.stream(model, {
41
+ messages: [{ role: 'user', content: 'Hello', timestamp: Date.now() }],
42
+ });
43
+
44
+ for await (const event of result) {
45
+ if (event.type === 'text_delta') {
46
+ process.stdout.write(event.delta);
47
+ }
48
+ }
49
+ ```
50
+
51
+ ### Through `agentic-kit`
52
+
53
+ `agentic-kit` pre-registers an OpenAI adapter with no key. Replace it with a
54
+ configured one:
55
+
56
+ ```ts
57
+ import { registerProvider, stream, getModel } from 'agentic-kit';
58
+ import { OpenAIAdapter } from '@agentic-kit/openai';
59
+
60
+ registerProvider(new OpenAIAdapter({ apiKey: process.env.OPENAI_API_KEY! }));
61
+
62
+ const model = getModel('openai', 'gpt-5.4-mini')!;
63
+ const result = stream(model, { messages: [...] });
64
+ ```
65
+
66
+ ### Pointing at an OpenAI-compatible endpoint
67
+
68
+ ```ts
69
+ const lmStudio = new OpenAIAdapter({
70
+ baseUrl: 'http://localhost:1234/v1',
71
+ provider: 'lmstudio',
72
+ reasoning: false,
73
+ tools: true,
74
+ compat: {
75
+ maxTokensField: 'max_tokens',
76
+ reasoningFormat: 'none',
77
+ supportsStrictToolSchema: false,
78
+ supportsUsageInStreaming: false,
79
+ },
80
+ });
81
+ const model = lmStudio.createModel('llama-3.1-8b-instruct');
82
+ ```
83
+
84
+ ## API Reference
85
+
86
+ ### `new OpenAIAdapter(options? | apiKey?)`
87
+
88
+ `OpenAIOptions`:
89
+
90
+ - `apiKey` — required for hosted OpenAI; optional for unauthenticated local
91
+ endpoints.
92
+ - `baseUrl` — defaults to `https://api.openai.com/v1`.
93
+ - `defaultModel` — defaults to `gpt-5.4-mini`.
94
+ - `provider` — registry key; defaults to `'openai'`. Set to your own value
95
+ (e.g. `'lmstudio'`) when registering alongside the OpenAI adapter.
96
+ - `defaultInput` — input modalities for ad-hoc models. Defaults to
97
+ `['text', 'image']`.
98
+ - `reasoning`, `tools` — capability defaults for ad-hoc models.
99
+ - `contextWindow`, `maxTokens` — defaults for ad-hoc models.
100
+ - `headers` — extra headers on every request.
101
+ - `compat` — `OpenAICompatibleCompat` overrides applied to every model
102
+ produced by this adapter.
103
+
104
+ ### `OpenAICompatibleCompat`
105
+
106
+ Per-model quirks for non-OpenAI endpoints:
107
+
108
+ - `maxTokensField` — `'max_tokens'` or `'max_completion_tokens'`.
109
+ - `reasoningFormat` — `'openai'` or `'none'`.
110
+ - `supportsReasoningEffort` — whether the endpoint accepts the
111
+ `reasoning_effort` field.
112
+ - `supportsStrictToolSchema` — whether to send `strict: true` on tool defs.
113
+ - `supportsUsageInStreaming` — request usage in streaming payloads.
114
+ - `toolCallIdFormat` — `'passthrough' | 'safe64' | 'mistral9'` for endpoints
115
+ that constrain tool-call ids.
116
+ - `requiresToolResultName` — include `name` on `tool` messages (some
117
+ endpoints reject it, others require it).
118
+
119
+ ### `adapter.createModel(modelId, overrides?)`
120
+
121
+ Returns a `ModelDescriptor`. Built-ins in `OPENAI_COMPATIBLE_MODELS` are
122
+ used as a base when the id matches; otherwise a generic descriptor is
123
+ synthesized from the adapter's defaults.
124
+
125
+ ### `adapter.stream(model, context, options?)`
126
+
127
+ Returns an `AssistantMessageEventStream`. Supports the standard `agentic-kit`
128
+ `StreamOptions` (`apiKey`, `headers`, `maxTokens`, `temperature`,
129
+ `reasoning`, `onPayload`, `signal`).
130
+
131
+ ### `adapter.listModels()`
132
+
133
+ If an API key is configured, fetches `${baseUrl}/models`; otherwise returns
134
+ the built-in `OPENAI_COMPATIBLE_MODELS` entries for this adapter's provider.
135
+
136
+ ### `OPENAI_COMPATIBLE_MODELS`
137
+
138
+ Built-in descriptors for the GPT-5.4 tier (`gpt-5.4`, `gpt-5.4-mini`,
139
+ `gpt-5.4-nano`) with cost, context window, and `compat` metadata.
140
+
23
141
  ---
24
142
 
25
143
  ## Related Constructive Tooling