@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.
@@ -113,7 +113,10 @@ async function* streamFromOpenAI(client, req, options) {
113
113
  }
114
114
  if (req.temperature !== void 0) body.temperature = req.temperature;
115
115
  const effectiveMaxTokens = req.maxTokens ?? options.defaultMaxTokens;
116
- if (effectiveMaxTokens !== void 0) body.max_tokens = effectiveMaxTokens;
116
+ if (effectiveMaxTokens !== void 0) {
117
+ const param = options.tokensParam ?? (needsMaxCompletionTokens(req.model) ? "max_completion_tokens" : "max_tokens");
118
+ body[param] = effectiveMaxTokens;
119
+ }
117
120
  let stream;
118
121
  try {
119
122
  stream = await client.chat.completions.create(body, { signal: req.signal });
@@ -296,6 +299,9 @@ function capabilitiesFor(modelId, knownModels) {
296
299
  if (known) return known.capabilities;
297
300
  return defaultCapabilitiesForUnknown(modelId);
298
301
  }
302
+ function needsMaxCompletionTokens(modelId) {
303
+ return /^(o\d|gpt-5)/i.test(modelId);
304
+ }
299
305
  function defaultCapabilitiesForUnknown(modelId) {
300
306
  const isReasoning = /^o[13]([-/]|$)/i.test(modelId);
301
307
  if (isReasoning) {
@@ -1673,7 +1679,12 @@ var VertexOpenAIAdapter = class {
1673
1679
  stream(req) {
1674
1680
  return streamFromOpenAI(this.ensureClient(), req, {
1675
1681
  knownModels: vertexOpenAIManifest.knownModels,
1676
- defaultMaxTokens: 4096
1682
+ defaultMaxTokens: 4096,
1683
+ // Pin legacy `max_tokens`: Vertex's OpenAI-compat partner-model
1684
+ // endpoint predates `max_completion_tokens` and may not recognize it.
1685
+ // The model-id heuristic wouldn't catch a partner model named in the
1686
+ // OpenAI style (unlikely today, but defensive).
1687
+ tokensParam: "max_tokens"
1677
1688
  });
1678
1689
  }
1679
1690
  appendAssistantToolCall(history, toolCalls) {
@@ -2415,7 +2426,8 @@ var AzureOpenAIAdapter = class {
2415
2426
  }
2416
2427
  stream(req) {
2417
2428
  return streamFromOpenAI(this.ensureClient(), req, {
2418
- knownModels: azureOpenAIManifest.knownModels
2429
+ knownModels: azureOpenAIManifest.knownModels,
2430
+ tokensParam: "max_completion_tokens"
2419
2431
  });
2420
2432
  }
2421
2433
  appendAssistantToolCall(history, toolCalls) {
@@ -2434,7 +2446,12 @@ var AzureOpenAIAdapter = class {
2434
2446
  // still requires it as a parameter.
2435
2447
  model: "probe",
2436
2448
  messages: [{ role: "user", content: "ping" }],
2437
- max_tokens: 1,
2449
+ // Use `max_completion_tokens` (not legacy `max_tokens`): gpt-5 family
2450
+ // and o-series reasoning models return 400 on the legacy parameter.
2451
+ // The newer name is a superset — also accepted by gpt-4o, gpt-4-turbo,
2452
+ // and gpt-3.5-turbo deployments — so it's the safe choice for a probe
2453
+ // that has to work regardless of the underlying deployment model.
2454
+ max_completion_tokens: 1,
2438
2455
  stream: false
2439
2456
  });
2440
2457
  }