@jambonz/llm 0.4.0 → 0.4.1

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.
@@ -74,7 +74,10 @@ async function* streamFromOpenAI(client, req, options) {
74
74
  }
75
75
  if (req.temperature !== void 0) body.temperature = req.temperature;
76
76
  const effectiveMaxTokens = req.maxTokens ?? options.defaultMaxTokens;
77
- if (effectiveMaxTokens !== void 0) body.max_tokens = effectiveMaxTokens;
77
+ if (effectiveMaxTokens !== void 0) {
78
+ const param = options.tokensParam ?? (needsMaxCompletionTokens(req.model) ? "max_completion_tokens" : "max_tokens");
79
+ body[param] = effectiveMaxTokens;
80
+ }
78
81
  let stream;
79
82
  try {
80
83
  stream = await client.chat.completions.create(body, { signal: req.signal });
@@ -257,6 +260,9 @@ function capabilitiesFor(modelId, knownModels) {
257
260
  if (known) return known.capabilities;
258
261
  return defaultCapabilitiesForUnknown(modelId);
259
262
  }
263
+ function needsMaxCompletionTokens(modelId) {
264
+ return /^(o\d|gpt-5)/i.test(modelId);
265
+ }
260
266
  function defaultCapabilitiesForUnknown(modelId) {
261
267
  const isReasoning = /^o[13]([-/]|$)/i.test(modelId);
262
268
  if (isReasoning) {
@@ -1634,7 +1640,12 @@ var VertexOpenAIAdapter = class {
1634
1640
  stream(req) {
1635
1641
  return streamFromOpenAI(this.ensureClient(), req, {
1636
1642
  knownModels: vertexOpenAIManifest.knownModels,
1637
- defaultMaxTokens: 4096
1643
+ defaultMaxTokens: 4096,
1644
+ // Pin legacy `max_tokens`: Vertex's OpenAI-compat partner-model
1645
+ // endpoint predates `max_completion_tokens` and may not recognize it.
1646
+ // The model-id heuristic wouldn't catch a partner model named in the
1647
+ // OpenAI style (unlikely today, but defensive).
1648
+ tokensParam: "max_tokens"
1638
1649
  });
1639
1650
  }
1640
1651
  appendAssistantToolCall(history, toolCalls) {
@@ -2382,7 +2393,8 @@ var AzureOpenAIAdapter = class {
2382
2393
  }
2383
2394
  stream(req) {
2384
2395
  return streamFromOpenAI(this.ensureClient(), req, {
2385
- knownModels: azureOpenAIManifest.knownModels
2396
+ knownModels: azureOpenAIManifest.knownModels,
2397
+ tokensParam: "max_completion_tokens"
2386
2398
  });
2387
2399
  }
2388
2400
  appendAssistantToolCall(history, toolCalls) {
@@ -2401,7 +2413,12 @@ var AzureOpenAIAdapter = class {
2401
2413
  // still requires it as a parameter.
2402
2414
  model: "probe",
2403
2415
  messages: [{ role: "user", content: "ping" }],
2404
- max_tokens: 1,
2416
+ // Use `max_completion_tokens` (not legacy `max_tokens`): gpt-5 family
2417
+ // and o-series reasoning models return 400 on the legacy parameter.
2418
+ // The newer name is a superset — also accepted by gpt-4o, gpt-4-turbo,
2419
+ // and gpt-3.5-turbo deployments — so it's the safe choice for a probe
2420
+ // that has to work regardless of the underlying deployment model.
2421
+ max_completion_tokens: 1,
2405
2422
  stream: false
2406
2423
  });
2407
2424
  }