Commit Graph

388 Commits

Author SHA1 Message Date
Armin Ronacher ae9450dc51 chore(ts): use source import extensions 2026-05-20 00:04:03 +02:00
Mario Zechner 2787b601d7 fix(ai): stop defaulting max token request caps
closes #4675
2026-05-19 11:49:44 +02:00
Mario Zechner 7be75baded fix(ai): clamp OpenAI prompt cache keys
closes #4720
2026-05-19 10:51:11 +02:00
Mario Zechner 9e2bfc7c40 fix(ai): skip unknown bedrock content blocks
closes #4223
2026-05-18 01:42:18 +02:00
Mario Zechner 52e13870a1 fix(ai): prefix HTTP status codes onto Azure OpenAI and OpenAI Responses error messages so auto-retry fires on 5xx/429
closes #4232
2026-05-18 01:11:23 +02:00
Mario Zechner 21d80deda2 fix(ai): normalize opencode go reasoning replay
closes #4251
2026-05-18 01:11:23 +02:00
Mario Zechner b256ac7d77 Closes #4342 2026-05-17 23:55:25 +02:00
Mario Zechner 6d474f8c1a fix(ai): cap context-sized default output budgets
closes #4614
2026-05-17 20:06:59 +02:00
Mario Zechner 22a9c484e7 fix(ai): respect model output token limits
closes #4539
2026-05-16 23:33:06 +02:00
Mario Zechner 0412f62f9e Merge pull request #4558 from earendil-works/fix/openai-completions-throw-on-missing-finish_reason
fix(ai): openai-completions - throw error on missing finish-reason
2026-05-16 22:54:42 +02:00
Armin Ronacher 87881ca686 fix(ai): preserve OpenRouter cached token semantics 2026-05-16 11:55:16 +02:00
Ramiz Wachtler 98ffad0437 fix(ai): openai-completions - throw error on missing finish-reason
- require \ before treating \ streams as successful
- add regression coverage for truncated streams without \
- closes #4345
2026-05-15 15:26:57 +02:00
Ramiz Wachtler 0ae909316a fix(ai): honor retry-after for OpenAI Codex SSE retries
- honor `retry-after-ms` and `retry-after` for OpenAI Codex SSE retries
- add SSE retry coverage for millisecond, seconds, date, and fallback delays
2026-05-13 19:44:07 +02:00
Mario Zechner a5cca409d8 refactor(ai): use HTTP proxy agents for Bedrock 2026-05-13 16:12:48 +02:00
Mario Zechner f6b6b1f052 Merge pull request #4354 from haoqixu/fix-bun-ws-proxy
fix(ai): respect proxy envs in bun's websocket
2026-05-10 18:03:48 +02:00
yanirz 99dc6fcec8 fix(ai): add session affinity and compat fixes for Fireworks provider caching
Fireworks prompt caching is enabled by default (automatic prefix matching),
but on serverless infrastructure, requests hit random replicas. Without
session affinity, the per-replica cache misses, negating cache hit rates
and the discounted cacheRead pricing.

Changes:

- Add sendSessionAffinityHeaders and supportsCacheControlOnTools
  to AnthropicMessagesCompat interface
- Send x-session-affinity header for Fireworks (and Cloudflare AI
  Gateway Anthropic) when sessionId is available and caching is enabled
- Omit cache_control on tool definitions for Fireworks (unsupported
  per https://docs.fireworks.ai/tools-sdks/anthropic-compatibility)
- Default supportsEagerToolInputStreaming to false for Fireworks
  (unsupported field)
- Default supportsLongCacheRetention to false for Fireworks
  (cache_control.ttl not supported)
- Add compat settings to Fireworks models in generate-models.ts
- Update generated models with Fireworks compat settings
- Add integration tests for session affinity and tool compat

Refs: https://docs.fireworks.ai/guides/prompt-caching
Refs: https://docs.fireworks.ai/tools-sdks/anthropic-compatibility
2026-05-10 00:11:36 +02:00
haoqixu 8c2e3eddec fix(ai): respect proxy envs in bun's websocket
fixes #4346
2026-05-10 03:43:07 +08:00
Mario Zechner 7adb8e7634 feat(ai): add Together AI provider 2026-05-08 16:44:18 +02:00
Cristina Poncela Cubeiro 8fa1194c23 fix: no fallback for apiKey 2026-05-08 11:23:15 +02:00
Cristina Poncela Cubeiro 0e4f845cf4 fix: lazy loading 2026-05-08 11:08:04 +02:00
Cristina Poncela Cubeiro ffdf426e33 Merge remote-tracking branch 'upstream/main' into feat/image-outputs 2026-05-07 16:46:17 +02:00
Cristina Poncela Cubeiro 32b2cd0720 delete: images() 2026-05-07 16:21:50 +02:00
Armin Ronacher 6b271842e2 fix(ai): handle mixed chat completion deltas
Fixes #4228
2026-05-07 00:12:19 +02:00
Mario Zechner 31f5c23271 fix(ai): handle OpenAI Responses reasoning text deltas 2026-05-06 00:08:26 +02:00
Mario Zechner 15aa313501 Closes #4184, codex needs a non-empty system prompt 2026-05-05 14:50:27 +02:00
Cristina Poncela Cubeiro 60e885f985 refactor: image providers into subfolder 2026-05-05 09:30:15 +02:00
Cristina Poncela Cubeiro 5731e13a61 Merge branch 'main' into feat/image-outputs 2026-05-04 16:42:51 +01:00
Cristina Poncela Cubeiro b9c19135d9 cleanup 2026-05-04 17:10:44 +02:00
Cristina Poncela Cubeiro d9adc536f5 feat: openrouter images 2026-05-04 17:00:58 +02:00
Cristina Poncela Cubeiro cbf3c333ef revert 2026-05-04 15:43:45 +02:00
Mario Zechner 23420012ab fix(coding-agent): decouple codex session cleanup 2026-05-04 00:45:56 +02:00
Armin Ronacher 370fdae6fa fix(ai): fall back from codex websocket to sse (#4133) 2026-05-03 22:51:42 +02:00
Armin Ronacher b9efafc535 fix(ci): repair failing test expectations 2026-05-03 00:04:27 +02:00
Mario Zechner b8bb2411ff fix(ai): honor codex transport option
closes #4083
2026-05-02 14:14:22 +02:00
Mario Zechner 80f06d3636 feat: add model thinking level metadata
closes #3208
2026-05-02 01:21:06 +02:00
Mario Zechner 4745a95898 feat(ai): add cached codex websocket transport 2026-05-01 13:07:40 +02:00
Mario Zechner a45577bd00 fix(ai): finalize cloudflare gateway provider support 2026-05-01 00:56:05 +02:00
MC 24fb6b833b feat(ai): add Cloudflare AI Gateway as a provider (#3856)
* feat(ai): add Cloudflare AI Gateway as a provider

Routes through Cloudflare's Unified API (`/compat`) for Workers AI and
Anthropic models, and through the provider-specific `/openai` subpath
for OpenAI models so reasoning models (gpt-5.x, o-series) can hit
`/v1/responses` natively. Once `/compat` adds Responses-API support,
the OpenAI subpath can be folded back in.

Catalog layout:
  workers-ai/@cf/...  -> openai-completions, gateway/.../compat
  anthropic/...       -> openai-completions, gateway/.../compat
  <native-id>         -> openai-responses,   gateway/.../openai
                         (gpt-5.1, claude-... no, sorry: gpt-5.x and o-series only;
                          prefix stripped because the OpenAI SDK posts native ids)

Touches:
  packages/ai/src/types.ts                       add cloudflare-ai-gateway to KnownProvider
  packages/ai/src/env-api-keys.ts                map to CLOUDFLARE_API_KEY
  packages/ai/src/providers/cloudflare.ts        add CLOUDFLARE_AI_GATEWAY_COMPAT_BASE_URL
                                                 and CLOUDFLARE_AI_GATEWAY_OPENAI_BASE_URL
  packages/ai/src/providers/openai-responses.ts  one-line dispatch through resolveCloudflareBaseUrl
                                                 (matches what openai-completions.ts already does)
  packages/ai/scripts/generate-models.ts         branch openai/* vs workers-ai/anthropic/*
  packages/ai/src/models.generated.ts            spliced 34 entries
  packages/ai/test/stream.test.ts                3 e2e blocks (one per upstream)
  packages/coding-agent/*                        defaultModelPerProvider, login, env docs,
                                                 README, providers.md

Verified end-to-end against a real Cloudflare account with unified
billing: 9/9 e2e tests pass across all three upstreams (Workers AI
Kimi K2.6, OpenAI gpt-5.1 reasoning, Anthropic claude-sonnet-4-5).

* refactor(ai): move AI Gateway User-Agent and per-route session-affinity flag to catalog

Mirrors the same per-model metadata refactor done for Workers AI in the
parent branch. All cloudflare-ai-gateway entries get the User-Agent
header. Only workers-ai/* gateway entries set
`compat.sendSessionAffinityHeaders: true` because the gateway
forwards that header to the underlying Workers AI runtime; anthropic/*
upstream and openai/* (openai-responses) don't use it.

  packages/ai/scripts/generate-models.ts: emit headers (always) and
  per-upstream compat (workers-ai only) on each cloudflare-ai-gateway
  entry.
  packages/ai/src/models.generated.ts: re-spliced 35 entries with
  headers + conditional compat.

Behavior unchanged - 9/9 e2e tests pass across all three upstream
families.

* fix(ai): align AI Gateway with telemetry-aware UA helper

Adapts to badlogic/pi-mono#3851's follow-up fix ("honor telemetry for
Cloudflare attribution headers", fbb5eed) which moved the
'User-Agent: pi-coding-agent' header out of per-model catalog metadata
and into a centralized telemetry-honoring helper
(coding-agent/src/core/sdk.ts:getAttributionHeaders).

- packages/coding-agent/src/core/sdk.ts: extend the cloudflare branch of
  getAttributionHeaders to also match cloudflare-ai-gateway and
  gateway.ai.cloudflare.com.

- packages/ai/scripts/generate-models.ts and src/models.generated.ts:
  drop 'headers' from the 35 cloudflare-ai-gateway entries (constant
  CLOUDFLARE_STATIC_HEADERS no longer exists). Per-route
  compat.sendSessionAffinityHeaders is unchanged.

End-to-end behavior unchanged: 9/9 tests still pass across all three
upstream families (Workers AI, Anthropic, OpenAI Responses).

---------

Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
2026-04-30 23:29:37 +02:00
Mario Zechner f7df474084 fix google vertex unsigned tool call replay closes #4032 2026-04-30 21:59:21 +02:00
Mario Zechner fe66edd943 remove gemini cli and antigravity support 2026-04-30 21:24:36 +02:00
Armin Ronacher 7dc1bed478 feat(ai): add Moonshot AI provider model support 2026-04-30 17:21:03 +02:00
Johannes Ebeling 779d0ef39d feat(ai): add Mistral Medium 3.5 model (#4009) 2026-04-30 12:18:17 +02:00
Alejandro e354c521f4 feat(ai): expose routed model on openai-completions (#3968)
Adds `AssistantMessage.responseModel` on the openai-completions path:
surfaces the concrete `chunk.model` when it differs from the requested
id (e.g. OpenRouter `auto` -> `anthropic/...`).
2026-04-30 00:16:12 +02:00
Mario Zechner 83592bb2df fix(ai): detect incomplete Anthropic streams
closes #3936
2026-04-29 23:30:29 +02:00
Mario Zechner d935a0f4f8 Closes #3900 2026-04-29 22:44:02 +02:00
Mario Zechner fc3cbedc6c fix(ai): track DeepSeek prompt cache hits
closes #3880
2026-04-29 16:37:39 +02:00
Cristina Poncela Cubeiro 59a89e0c1c fix: modalities from openrouter 2026-04-29 09:51:57 +02:00
Cristina Poncela Cubeiro c3c10737d8 feat: image content 2026-04-28 13:43:28 +02:00
Armin Ronacher ed4bc73080 fix(ai): normalize Bedrock model names for profiles 2026-04-28 11:23:31 +02:00
MC d6e08b3da0 feat(ai): add Cloudflare Workers AI as a provider (#3851)
* feat(ai): add Cloudflare Workers AI as a provider

Cloudflare Workers AI hosts open-weight LLMs (Kimi K2.6, GPT-OSS,
GLM-4.7, Llama 4, Gemma 4, Nemotron 3) on Cloudflare's GPU network with
an OpenAI-compatible endpoint. Reuses the openai-completions API
protocol; the per-account URL contains a {CLOUDFLARE_ACCOUNT_ID}
placeholder resolved at request time by a small helper.

Pi automatically sets x-session-affinity for prefix caching:
https://developers.cloudflare.com/workers-ai/features/prompt-caching/

Auth: CLOUDFLARE_API_KEY (matches pi's *_API_KEY convention) +
CLOUDFLARE_ACCOUNT_ID. The User-Agent identifies traffic as
'pi-coding-agent' in Cloudflare analytics.

Verified end-to-end against a real Cloudflare account: 17 e2e tests
pass across stream/empty/tokens/unicode/tool-call-without-result/
total-tokens against @cf/moonshotai/kimi-k2.6.

Cloudflare AI Gateway is a separate, larger change (it requires routing
through provider-specific subpaths with the matching API protocol per
upstream) and will land in a follow-up PR.

* refactor(ai): move Cloudflare User-Agent and session-affinity flag to per-model metadata

Instead of conditionally setting them in openai-completions.ts based on
provider detection, declare them as model-level fields in the catalog
(headers + compat). This is consistent with how the github-copilot and
kimi-coding entries already declare their static headers.

  packages/ai/scripts/generate-models.ts: emit headers and compat fields
  on each cloudflare-workers-ai entry (CLOUDFLARE_STATIC_HEADERS).
  packages/ai/src/providers/openai-completions.ts: drop the
  isCloudflareProvider conditional that injected User-Agent and the
  isCloudflareWorkersAI override of sendSessionAffinityHeaders.
  packages/ai/src/models.generated.ts: re-spliced 8 cloudflare-workers-ai
  entries with headers + compat.

Behavior is unchanged - verified via fetch interceptor that User-Agent
and x-session-affinity / session_id / x-client-request-id are still sent
on outbound requests. 5/5 e2e tests pass.
2026-04-27 23:41:54 +02:00