baikai 0.10.1.1 → 0.11.0.0
raw patch · 13 files changed
+720/−116 lines, 13 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Baikai.Content: AssistantText :: !TextContent -> AssistantContent
- Baikai.Content: AssistantToolCall :: !ToolCall -> AssistantContent
- Baikai.Prelude: ($dm_1) :: (Field1 s t a b, Generic s, Generic t, GIxed N0 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_10) :: (Field10 s t a b, Generic s, Generic t, GIxed N9 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_11) :: (Field11 s t a b, Generic s, Generic t, GIxed N10 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_12) :: (Field12 s t a b, Generic s, Generic t, GIxed N11 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_13) :: (Field13 s t a b, Generic s, Generic t, GIxed N12 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_14) :: (Field14 s t a b, Generic s, Generic t, GIxed N13 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_15) :: (Field15 s t a b, Generic s, Generic t, GIxed N14 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_16) :: (Field16 s t a b, Generic s, Generic t, GIxed N15 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_17) :: (Field17 s t a b, Generic s, Generic t, GIxed N16 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_18) :: (Field18 s t a b, Generic s, Generic t, GIxed N17 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_19) :: (Field19 s t a b, Generic s, Generic t, GIxed N18 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_2) :: (Field2 s t a b, Generic s, Generic t, GIxed N1 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_3) :: (Field3 s t a b, Generic s, Generic t, GIxed N2 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_4) :: (Field4 s t a b, Generic s, Generic t, GIxed N3 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_5) :: (Field5 s t a b, Generic s, Generic t, GIxed N4 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_6) :: (Field6 s t a b, Generic s, Generic t, GIxed N5 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_7) :: (Field7 s t a b, Generic s, Generic t, GIxed N6 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_8) :: (Field8 s t a b, Generic s, Generic t, GIxed N7 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_9) :: (Field9 s t a b, Generic s, Generic t, GIxed N8 (Rep s) (Rep t) a b) => Lens s t a b
- Baikai.Prelude: ($dm_Empty) :: (AsEmpty a, Monoid a, Eq a) => Prism' a ()
- Baikai.Prelude: ($dm_Wrapped') :: forall (d :: Meta) (c :: Meta) (s' :: Meta) a. (Wrapped s, Generic s, D1 d (C1 c (S1 s' (Rec0 a))) ~ Rep s, Unwrapped s ~ GUnwrapped (Rep s)) => Iso' s (Unwrapped s)
- Baikai.Prelude: ($dmeach) :: forall (g :: Type -> Type). (Each s t a b, Traversable g, s ~ g a, t ~ g b) => Traversal s t a b
- Baikai.Prelude: ($dmifoldMap) :: (FoldableWithIndex i f, TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m
- Baikai.Prelude: ($dmimap) :: (FunctorWithIndex i f, TraversableWithIndex i f) => (i -> a -> b) -> f a -> f b
- Baikai.Prelude: ($dmitraverse) :: (TraversableWithIndex i t, i ~ Int, Applicative f) => (i -> a -> f b) -> t a -> f (t b)
- Baikai.Prelude: ($dmix) :: (Ixed m, At m) => Index m -> Traversal' m (IxValue m)
- Baikai.Prelude: ($dmparseJSON) :: (FromJSON a, Generic a, GFromJSON Zero (Rep a)) => Value -> Parser a
- Baikai.Prelude: ($dmplate) :: (Plated a, Data a) => Traversal' a a
- Baikai.Prelude: ($dmtoJSON) :: (ToJSON a, Generic a, GToJSON' Value Zero (Rep a)) => a -> Value
- Baikai.Prelude: infixl 5 `failing`
- Baikai.Prelude: infixl 8 ^#
- Baikai.Prelude: infixr 2 `zoom`
- Baikai.Prelude: infixr 4 ||~
- Baikai.Prelude: infixr 5 `cons`
- Baikai.Prelude: infixr 8 #
- Baikai.Prelude: infixr 9 ...
+ Baikai.Compat: AnthropicPrefillRequiresThinkingOff :: AnthropicAssistantPrefillPolicy
+ Baikai.Compat: AnthropicPrefillUnsupported :: AnthropicAssistantPrefillPolicy
+ Baikai.Compat: data AnthropicAssistantPrefillPolicy
+ Baikai.Compat: instance Data.Aeson.Types.FromJSON.FromJSON Baikai.Compat.AnthropicAssistantPrefillPolicy
+ Baikai.Compat: instance Data.Aeson.Types.ToJSON.ToJSON Baikai.Compat.AnthropicAssistantPrefillPolicy
+ Baikai.Compat: instance GHC.Classes.Eq Baikai.Compat.AnthropicAssistantPrefillPolicy
+ Baikai.Compat: instance GHC.Internal.Generics.Generic Baikai.Compat.AnthropicAssistantPrefillPolicy
+ Baikai.Compat: instance GHC.Internal.Show.Show Baikai.Compat.AnthropicAssistantPrefillPolicy
+ Baikai.Content: OutputItemReplay :: !Api -> !Text -> !Value -> OutputItemReplay
+ Baikai.Content: [outputReplayApi] :: OutputItemReplay -> !Api
+ Baikai.Content: [outputReplayItem] :: OutputItemReplay -> !Value
+ Baikai.Content: [outputReplayModel] :: OutputItemReplay -> !Text
+ Baikai.Content: data OutputItemReplay
+ Baikai.Content: instance Data.Aeson.Types.FromJSON.FromJSON Baikai.Content.OutputItemReplay
+ Baikai.Content: instance Data.Aeson.Types.ToJSON.ToJSON Baikai.Content.OutputItemReplay
+ Baikai.Content: instance GHC.Classes.Eq Baikai.Content.OutputItemReplay
+ Baikai.Content: instance GHC.Internal.Generics.Generic Baikai.Content.OutputItemReplay
+ Baikai.Content: instance GHC.Internal.Show.Show Baikai.Content.OutputItemReplay
+ Baikai.Content: outputItemReplay :: AssistantContent -> Maybe OutputItemReplay
+ Baikai.Content: pattern AssistantText :: TextContent -> AssistantContent
+ Baikai.Content: pattern AssistantToolCall :: ToolCall -> AssistantContent
+ Baikai.Content: withOutputItemReplay :: OutputItemReplay -> AssistantContent -> AssistantContent
+ Baikai.Models.Generated: anthropic_claude_fable_5_2 :: Model
+ Baikai.Models.Generated: openai_gpt_6_1_terra :: Model
+ Baikai.Models.Generated: openai_gpt_6_2_astra :: Model
+ Baikai.Models.Generated: openai_gpt_6_2_sol :: Model
+ Baikai.Prelude: Rec :: K1 R a x -> Rec p a (x :: k)
+ Baikai.Prelude: _As :: AsAny sel a s => Prism s s a a
+ Baikai.Prelude: _Ctor :: AsConstructor ctor s t a b => Prism s t a b
+ Baikai.Prelude: _Ctor' :: AsConstructor' ctor s a => Prism s s a a
+ Baikai.Prelude: _Ctor0 :: AsConstructor0 ctor s t a b => Prism s t a b
+ Baikai.Prelude: _Ctor_ :: AsConstructor_ ctor s t a b => Prism s t a b
+ Baikai.Prelude: _Sub :: AsSubtype sub sup => Prism' sup sub
+ Baikai.Prelude: _Typed :: AsType a s => Prism' s a
+ Baikai.Prelude: class AsAny (sel :: k) a s | s sel -> a
+ Baikai.Prelude: class AsConstructor (ctor :: Symbol) s t a b | ctor s -> a, ctor t -> b
+ Baikai.Prelude: class AsConstructor' (ctor :: Symbol) s a | ctor s -> a
+ Baikai.Prelude: class AsConstructor0 (ctor :: Symbol) s t a b
+ Baikai.Prelude: class AsConstructor_ (ctor :: Symbol) s t a b
+ Baikai.Prelude: class AsSubtype sub sup
+ Baikai.Prelude: class AsType a s
+ Baikai.Prelude: class HasAny (sel :: k) s t a b | s sel -> a
+ Baikai.Prelude: class HasField (field :: Symbol) s t a b | s field -> a, t field -> b, s field b -> t, t field a -> s
+ Baikai.Prelude: class HasField' (field :: Symbol) s a | s field -> a
+ Baikai.Prelude: class HasField_ (field :: Symbol) s t a b
+ Baikai.Prelude: class HasParam (p :: Nat) s t a b | p t a -> s, p s b -> t, p s -> a, p t -> b
+ Baikai.Prelude: class HasPosition (i :: Nat) s t a b | s i -> a, t i -> b, s i b -> t, t i a -> s
+ Baikai.Prelude: class HasPosition' (i :: Nat) s a | s i -> a
+ Baikai.Prelude: class HasPosition0 (i :: Nat) s t a b
+ Baikai.Prelude: class HasPosition_ (i :: Nat) s t a b
+ Baikai.Prelude: class HasType a s
+ Baikai.Prelude: class HasTypes s a
+ Baikai.Prelude: class HasTypesCustom ch s t a b
+ Baikai.Prelude: class HasTypesUsing ch s t a b
+ Baikai.Prelude: class IsList f g (as :: [Type]) (bs :: [Type]) | f -> as, g -> bs
+ Baikai.Prelude: class Subtype sup sub
+ Baikai.Prelude: data ChGeneric
+ Baikai.Prelude: data family Param :: Nat -> j -> k
+ Baikai.Prelude: field :: HasField field s t a b => Lens s t a b
+ Baikai.Prelude: field' :: HasField' field s a => Lens s s a a
+ Baikai.Prelude: field_ :: HasField_ field s t a b => Lens s t a b
+ Baikai.Prelude: getField :: forall (f :: Symbol) a s. HasField' f s a => s -> a
+ Baikai.Prelude: getPosition :: forall (i :: Nat) s a. HasPosition' i s a => s -> a
+ Baikai.Prelude: getTyped :: HasType a s => s -> a
+ Baikai.Prelude: injectSub :: AsSubtype sub sup => sub -> sup
+ Baikai.Prelude: injectTyped :: AsType a s => a -> s
+ Baikai.Prelude: list :: IsList f g as bs => Iso f g (HList as) (HList bs)
+ Baikai.Prelude: newtype Rec p a (x :: k)
+ Baikai.Prelude: param :: HasParam p s t a b => Traversal s t a b
+ Baikai.Prelude: position :: HasPosition i s t a b => Lens s t a b
+ Baikai.Prelude: position' :: HasPosition' i s a => Lens s s a a
+ Baikai.Prelude: position0 :: HasPosition0 i s t a b => Lens s t a b
+ Baikai.Prelude: position_ :: HasPosition_ i s t a b => Lens s t a b
+ Baikai.Prelude: projectSub :: AsSubtype sub sup => sup -> Maybe sub
+ Baikai.Prelude: projectTyped :: AsType a s => s -> Maybe a
+ Baikai.Prelude: setField :: forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
+ Baikai.Prelude: setPosition :: forall (i :: Nat) s a. HasPosition' i s a => a -> s -> s
+ Baikai.Prelude: setTyped :: HasType a s => a -> s -> s
+ Baikai.Prelude: smash :: Subtype sup sub => sup -> sub -> sub
+ Baikai.Prelude: super :: Subtype sup sub => Lens sub sub sup sup
+ Baikai.Prelude: the :: HasAny sel s t a b => Lens s t a b
+ Baikai.Prelude: typed :: HasType a s => Lens s s a a
+ Baikai.Prelude: types :: forall a s. HasTypes s a => Traversal' s a
+ Baikai.Prelude: typesCustom :: HasTypesCustom ch s t a b => Traversal s t a b
+ Baikai.Prelude: typesUsing :: forall ch a s. HasTypesUsing ch s s a a => Traversal' s a
+ Baikai.Prelude: upcast :: Subtype sup sub => sub -> sup
- Baikai.Prelude: infixl 1 ??
+ Baikai.Prelude: infixl 1 <&>
- Baikai.Prelude: type family Zoomed (m :: Type -> Type) :: Type -> Type -> Type
+ Baikai.Prelude: type family Children ch a :: [Type]
Files
- CHANGELOG.md +99/−0
- baikai.cabal +1/−1
- data/models/anthropic.json +62/−14
- data/models/openai.json +81/−0
- fetch/FetchModelsCore.hs +77/−16
- gen/GenModelsCore.hs +25/−10
- src/Baikai/Compat.hs +22/−5
- src/Baikai/Content.hs +81/−6
- src/Baikai/Models/Generated.hs +198/−28
- test/CatalogSpec.hs +25/−22
- test/EmbeddingSpec.hs +23/−11
- test/FetchModelsSpec.hs +7/−3
- test/PricingPolicySpec.hs +19/−0
CHANGELOG.md view
@@ -7,6 +7,105 @@ ## [Unreleased] +## [baikai 0.11.0.0] - 2026-11-23++### Added++- Add `anthropic_claude_fable_5_2` on Claude Messages with adaptive thinking,+ client function tools, and structured output for eligible organizations.+ Standard rates per million tokens are $8 input, $40 output, $0.20 cache+ read, $10 five-minute cache write, and $16 one-hour cache write. Fast mode+ doubles those rates.+- Add `openai_gpt_6_2_astra` and `openai_gpt_6_2_sol` on OpenAI Responses+ with structured output, function tools, and Standard pricing for both+ cache durations and long-context requests.+- Add `openai_gpt_6_1_terra` on OpenAI Responses with explicit reasoning+ and cache compatibility, 30-minute and 12-hour cache-write prices, and+ whole-request pricing above 272,000 input tokens.++### Changed (breaking)++- `AssistantContent` changes its `Generic` representation to carry original+ Responses items. `AssistantText` and `AssistantToolCall` are bundled pattern+ synonyms. Existing persisted content still decodes.++### Fixed++- Apply the published long-context tier for GPT-5.6 Sol, its `gpt-5.6`+ alias, GPT-5.6 Terra, and GPT-5.6 Luna. Use the published one-hour write+ rates for eight Claude bindings that used the five-minute rate.++## [baikai-claude 0.7.3.1] - 2026-11-23++### Changed++- Use `claude-hs 0.1.0.0` for the Messages transport and require+ `baikai ^>=0.11.0.0`. Fable 5.2 tool continuations preserve signed+ thinking, including empty signed blocks.++### Fixed++- Reject unsupported assistant prefills before dispatch. Claude 4.5 accepts+ prefills with effective thinking off. Normal tool-result continuations+ preserve prior assistant history.++## [baikai-openai 0.7.4.0] - 2026-11-23++### Added++- Expose `Baikai.Provider.OpenAI.HookEvidence` for Codex app-server clients+ to verify a reviewed pre-tool handler and decode its completion outcome.+- Add scoped Codex batch completion with reviewed PreToolUse hooks and+ native denial evidence.++### Changed++- Require `baikai ^>=0.11.0.0` for persisted Responses replay.++### Fixed++- Preserve completed Responses message and function-call items in stateless+ history. GPT-6.2 keeps reusable system prompts at the head of the input+ across tool turns.++## [baikai-typesafe 0.1.0.2] - 2026-11-23++### Changed++- Build against `baikai ^>=0.11.0.0`.++## [baikai-trace-otel 0.4.1.2] - 2026-11-23++### Changed++- Build against `baikai ^>=0.11.0.0`.++## [baikai-effectful 0.5.0.1] - 2026-11-23++### Changed++- Build against `baikai ^>=0.11.0.0`.++## [baikai-kit 0.4.0.4] - 2026-11-23++### Changed++- Build against `baikai ^>=0.11.0.0`.++## [baikai-agent 0.3.0.0] - 2026-11-23++### Added++- `baikai agent review-codex-hooks` presents exact native declarations for+ approval. `baikai agent run --codex-hooks` reports denials from the+ checked app-server thread in the JSON result.++### Changed (breaking)++- `AgentCliCommand` gains `AgentReviewCodexHooks`. Add that case to+ exhaustive matches. The runner requires `baikai ^>=0.11.0.0` and+ `baikai-openai ^>=0.7.4.0`.+ ## [baikai-openai 0.7.3.1] - 2026-11-14 ### Fixed
baikai.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.4 name: baikai-version: 0.10.1.1+version: 0.11.0.0 synopsis: Unified Haskell interface for multiple AI providers description: baikai provides a unified, provider-agnostic Haskell interface for working
data/models/anthropic.json view
@@ -17,13 +17,15 @@ }, "contextWindow": 1000000, "maxOutputTokens": 128000,+ "pricingPolicy": {"inputTiers": [], "longCacheWriteCost": 20.0}, "compat": { "kind": "anthropic-messages", "thinkingStyle": "adaptive", "supportsSamplingParameters": false, "supportsFastMode": false, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": false+ "supportsThinkingDisabled": false,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true },@@ -47,11 +49,38 @@ "supportsSamplingParameters": false, "supportsFastMode": false, "supportsForcedToolChoice": false,- "supportsThinkingDisabled": false+ "supportsThinkingDisabled": false,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true }, {+ "id": "claude-fable-5-2",+ "name": "Claude Fable 5.2",+ "reasoning": true,+ "input": ["text", "image"],+ "cost": {+ "input": 8.0,+ "output": 40.0,+ "cacheRead": 0.2,+ "cacheWrite": 10.0+ },+ "contextWindow": 1000000,+ "maxOutputTokens": 128000,+ "fastModeCost": {"input": 16.0, "output": 80.0, "cacheRead": 0.4, "cacheWrite": 20.0},+ "pricingPolicy": {"inputTiers": [], "longCacheWriteCost": 16.0},+ "compat": {+ "kind": "anthropic-messages",+ "thinkingStyle": "adaptive",+ "supportsSamplingParameters": false,+ "supportsFastMode": true,+ "supportsForcedToolChoice": false,+ "supportsThinkingDisabled": false,+ "assistantPrefillPolicy": "unsupported"+ },+ "enabled": true+ },+ { "id": "claude-haiku-4-5", "name": "Claude Haiku 4.5", "reasoning": true,@@ -64,13 +93,15 @@ }, "contextWindow": 200000, "maxOutputTokens": 64000,+ "pricingPolicy": {"inputTiers": [], "longCacheWriteCost": 2.0}, "compat": { "kind": "anthropic-messages", "thinkingStyle": "budget", "supportsSamplingParameters": true, "supportsFastMode": false, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": true+ "supportsThinkingDisabled": true,+ "assistantPrefillPolicy": "requires-thinking-off" }, "enabled": true },@@ -94,7 +125,8 @@ "supportsSamplingParameters": false, "supportsFastMode": false, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": true+ "supportsThinkingDisabled": true,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true },@@ -111,13 +143,15 @@ }, "contextWindow": 200000, "maxOutputTokens": 64000,+ "pricingPolicy": {"inputTiers": [], "longCacheWriteCost": 10.0}, "compat": { "kind": "anthropic-messages", "thinkingStyle": "budget", "supportsSamplingParameters": true, "supportsFastMode": false, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": true+ "supportsThinkingDisabled": true,+ "assistantPrefillPolicy": "requires-thinking-off" }, "enabled": true },@@ -134,13 +168,15 @@ }, "contextWindow": 1000000, "maxOutputTokens": 128000,+ "pricingPolicy": {"inputTiers": [], "longCacheWriteCost": 10.0}, "compat": { "kind": "anthropic-messages", "thinkingStyle": "adaptive", "supportsSamplingParameters": true, "supportsFastMode": false, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": true+ "supportsThinkingDisabled": true,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true },@@ -157,13 +193,15 @@ }, "contextWindow": 1000000, "maxOutputTokens": 128000,+ "pricingPolicy": {"inputTiers": [], "longCacheWriteCost": 10.0}, "compat": { "kind": "anthropic-messages", "thinkingStyle": "adaptive", "supportsSamplingParameters": false, "supportsFastMode": false, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": true+ "supportsThinkingDisabled": true,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true },@@ -188,7 +226,8 @@ "supportsSamplingParameters": false, "supportsFastMode": true, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": true+ "supportsThinkingDisabled": true,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true },@@ -213,7 +252,8 @@ "supportsSamplingParameters": false, "supportsFastMode": true, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": true+ "supportsThinkingDisabled": true,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true },@@ -238,7 +278,8 @@ "supportsSamplingParameters": false, "supportsFastMode": true, "supportsForcedToolChoice": false,- "supportsThinkingDisabled": false+ "supportsThinkingDisabled": false,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true },@@ -255,13 +296,15 @@ }, "contextWindow": 200000, "maxOutputTokens": 64000,+ "pricingPolicy": {"inputTiers": [], "longCacheWriteCost": 6.0}, "compat": { "kind": "anthropic-messages", "thinkingStyle": "budget", "supportsSamplingParameters": true, "supportsFastMode": false, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": true+ "supportsThinkingDisabled": true,+ "assistantPrefillPolicy": "requires-thinking-off" }, "enabled": true },@@ -278,13 +321,15 @@ }, "contextWindow": 1000000, "maxOutputTokens": 128000,+ "pricingPolicy": {"inputTiers": [], "longCacheWriteCost": 6.0}, "compat": { "kind": "anthropic-messages", "thinkingStyle": "adaptive", "supportsSamplingParameters": true, "supportsFastMode": false, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": true+ "supportsThinkingDisabled": true,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true },@@ -301,13 +346,15 @@ }, "contextWindow": 1000000, "maxOutputTokens": 128000,+ "pricingPolicy": {"inputTiers": [], "longCacheWriteCost": 4.0}, "compat": { "kind": "anthropic-messages", "thinkingStyle": "adaptive", "supportsSamplingParameters": false, "supportsFastMode": false, "supportsForcedToolChoice": true,- "supportsThinkingDisabled": true+ "supportsThinkingDisabled": true,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true },@@ -331,7 +378,8 @@ "supportsSamplingParameters": false, "supportsFastMode": false, "supportsForcedToolChoice": false,- "supportsThinkingDisabled": false+ "supportsThinkingDisabled": false,+ "assistantPrefillPolicy": "unsupported" }, "enabled": true }
data/models/openai.json view
@@ -247,6 +247,7 @@ }, "contextWindow": 1050000, "maxOutputTokens": 128000,+ "pricingPolicy": {"inputTiers": [{"inputAbove": 272000, "rates": {"input": 8.0, "output": 30.0, "cacheRead": 0.8, "cacheWrite": 10.0}}]}, "enabled": true, "compat": { "kind": "openai-completions",@@ -266,6 +267,7 @@ }, "contextWindow": 1050000, "maxOutputTokens": 128000,+ "pricingPolicy": {"inputTiers": [{"inputAbove": 272000, "rates": {"input": 0.4, "output": 1.8, "cacheRead": 0.04, "cacheWrite": 0.5}}]}, "enabled": true }, {@@ -281,6 +283,7 @@ }, "contextWindow": 1050000, "maxOutputTokens": 128000,+ "pricingPolicy": {"inputTiers": [{"inputAbove": 272000, "rates": {"input": 8.0, "output": 30.0, "cacheRead": 0.8, "cacheWrite": 10.0}}]}, "enabled": true }, {@@ -296,6 +299,7 @@ }, "contextWindow": 1050000, "maxOutputTokens": 128000,+ "pricingPolicy": {"inputTiers": [{"inputAbove": 272000, "rates": {"input": 4.0, "output": 18.0, "cacheRead": 0.4, "cacheWrite": 5.0}}]}, "enabled": true }, {@@ -394,6 +398,83 @@ "supportsSamplingParameters": false, "supportsLongCacheRetention": false, "supportsPromptCacheOptions": true,+ "supportedReasoningEfforts": ["low", "medium", "high", "xhigh", "max"]+ },+ "enabled": true+ },+ {+ "id": "gpt-6.1-terra",+ "name": "GPT-6.1 Terra",+ "reasoning": true,+ "input": ["text", "image"],+ "cost": {+ "input": 1.0,+ "output": 5.0,+ "cacheRead": 0.05,+ "cacheWrite": 1.25+ },+ "contextWindow": 1050000,+ "maxOutputTokens": 128000,+ "api": "openai-responses",+ "pricingPolicy": {"inputTiers": [{"inputAbove": 272000, "rates": {"input": 2.0, "output": 7.5, "cacheRead": 0.1, "cacheWrite": 2.5}, "longCacheWriteCost": 5.0}], "longCacheWriteCost": 2.5},+ "compat": {+ "kind": "openai-responses",+ "supportsSamplingParameters": false,+ "supportsLongCacheRetention": true,+ "supportsPromptCacheOptions": true,+ "nativeCachePolicy": {"contents":[true,true],"tag":"NativeCacheModern"},+ "supportedReasoningEfforts": ["none", "low", "medium", "high", "xhigh", "max"]+ },+ "enabled": true+ },+ {+ "id": "gpt-6.2-astra",+ "name": "GPT-6.2 Astra",+ "reasoning": true,+ "input": ["text", "image"],+ "cost": {+ "input": 8.0,+ "output": 40.0,+ "cacheRead": 0.4,+ "cacheWrite": 10.0+ },+ "contextWindow": 1050000,+ "maxOutputTokens": 128000,+ "api": "openai-responses",+ "pricingPolicy": {"inputTiers": [{"inputAbove": 272000, "rates": {"input": 16.0, "output": 60.0, "cacheRead": 0.8, "cacheWrite": 20.0}, "longCacheWriteCost": 40.0}], "longCacheWriteCost": 20.0},+ "compat": {+ "kind": "openai-responses",+ "supportsSamplingParameters": false,+ "supportsLongCacheRetention": true,+ "supportsPromptCacheOptions": true,+ "systemPromptInInput": true,+ "nativeCachePolicy": {"contents":[true,true],"tag":"NativeCacheModern"},+ "supportedReasoningEfforts": ["low", "medium", "high", "xhigh", "max"]+ },+ "enabled": true+ },+ {+ "id": "gpt-6.2-sol",+ "name": "GPT-6.2 Sol",+ "reasoning": true,+ "input": ["text", "image"],+ "cost": {+ "input": 2.0,+ "output": 10.0,+ "cacheRead": 0.1,+ "cacheWrite": 2.5+ },+ "contextWindow": 1050000,+ "maxOutputTokens": 128000,+ "api": "openai-responses",+ "pricingPolicy": {"inputTiers": [{"inputAbove": 272000, "rates": {"input": 4.0, "output": 15.0, "cacheRead": 0.2, "cacheWrite": 5.0}, "longCacheWriteCost": 10.0}], "longCacheWriteCost": 5.0},+ "compat": {+ "kind": "openai-responses",+ "supportsSamplingParameters": false,+ "supportsLongCacheRetention": true,+ "supportsPromptCacheOptions": true,+ "systemPromptInInput": true,+ "nativeCachePolicy": {"contents":[true,true],"tag":"NativeCacheModern"}, "supportedReasoningEfforts": ["low", "medium", "high", "xhigh", "max"] }, "enabled": true
fetch/FetchModelsCore.hs view
@@ -65,7 +65,7 @@ ) where -import Baikai.Compat (AnthropicThinkingStyle (..), NativeCachePolicy (..), OpenAICompletionsCompat (..), OpenAIResponsesCompat (..), defaultOpenAICompletionsCompat, defaultOpenAIResponsesCompat)+import Baikai.Compat (AnthropicAssistantPrefillPolicy (..), AnthropicThinkingStyle (..), NativeCachePolicy (..), OpenAICompletionsCompat (..), OpenAIResponsesCompat (..), defaultOpenAICompletionsCompat, defaultOpenAIResponsesCompat) import Baikai.Model (InputModality (..)) import Baikai.Model qualified as Model import Baikai.Prelude@@ -193,12 +193,8 @@ } deriving stock (Eq, Show, Generic) --- | The two request-shaping facts every curated Anthropic model must--- state before it can enter the catalog. Which extended-thinking wire--- shape a generation accepts, and whether it accepts the sampling--- parameters @temperature@, @top_p@ and @top_k@, are facts about the--- generation that no amount of inspecting the model id or the base URL--- can recover; they are curated here and travel through the catalog+-- | Request-shaping facts every curated Anthropic model must state.+-- They travel through the catalog -- JSON into the generated 'Baikai.Compat.AnthropicMessagesCompat'. data AnthropicGenerationFacts = AnthropicGenerationFacts { thinkingStyle :: !AnthropicThinkingStyle,@@ -206,6 +202,7 @@ supportsForcedToolChoice :: !Bool, -- | Whether the generation accepts @thinking: {"type": "disabled"}@. supportsThinkingDisabled :: !Bool,+ assistantPrefillPolicy :: !AnthropicAssistantPrefillPolicy, fastModeCost :: !(Maybe CatalogCost) } deriving stock (Eq, Show, Generic)@@ -281,6 +278,9 @@ ("o4-mini", Just (CatalogOpenAICompat oSeriesFacts)), ("gpt-6-astra", Just (CatalogResponsesCompat astraResponsesFacts)), ("gpt-6.1-sol", Just (CatalogResponsesCompat gpt61ResponsesFacts)),+ ("gpt-6.1-terra", Just (CatalogResponsesCompat terraResponsesFacts)),+ ("gpt-6.2-astra", Just (CatalogResponsesCompat gpt62ResponsesFacts)),+ ("gpt-6.2-sol", Just (CatalogResponsesCompat gpt62ResponsesFacts)), ("gpt-6-sol", Just (CatalogResponsesCompat gpt6ResponsesFacts)), ("gpt-6-luna", Just (CatalogResponsesCompat lunaResponsesFacts)) ]@@ -337,6 +337,17 @@ -- https://developers.openai.com/api/docs/models/gpt-6.1-sol -- https://developers.openai.com/api/docs/guides/latest-model gpt61ResponsesFacts = astraResponsesFacts+ -- 2026-11-20: Terra requires Responses for tool calling, accepts none+ -- and low through max, and supports 30m and 12h cache retention. Keep+ -- the conservative sampling policy while reasoning can be enabled.+ -- https://developers.openai.com/api/docs/models/gpt-6.1-terra+ -- https://developers.openai.com/api/docs/guides/prompt-caching+ terraResponsesFacts = gpt6ResponsesFacts & #nativeCachePolicy .~ Just (NativeCacheModern True True) & #supportsLongCacheRetention .~ True+ -- 2026-11-20: GPT-6.2 puts reusable developer instructions in input+ -- and supports both modern cache durations.+ -- https://developers.openai.com/api/docs/guides/keep-prefix-unchanged+ -- https://developers.openai.com/api/docs/guides/prompt-caching+ gpt62ResponsesFacts = astraResponsesFacts & #nativeCachePolicy .~ Just (NativeCacheModern True True) & #supportsLongCacheRetention .~ True & #systemPromptInInput .~ True -- 2026-09-07: native tools require Responses; only modern 30m cache TTL. -- https://developers.openai.com/api/docs/guides/latest-model astraResponsesFacts =@@ -425,7 +436,12 @@ ("claude-fable-5", adaptiveNoSampling & #supportsThinkingDisabled .~ False), -- 2026-09-07: always-on adaptive thinking; omit sampling parameters. -- https://platform.claude.com/docs/en/models/fable-5-1/whats-new-fable-5-1- ("claude-fable-5-1", adaptiveNoSampling & #supportsForcedToolChoice .~ False & #supportsThinkingDisabled .~ False)+ ("claude-fable-5-1", adaptiveNoSampling & #supportsForcedToolChoice .~ False & #supportsThinkingDisabled .~ False),+ -- 2026-11-20: always-on adaptive thinking, no sampling or forced+ -- tool choice, and double standard rates in fast mode.+ -- https://platform.claude.com/docs/en/models/fable-5-2/migration-guide+ -- https://platform.claude.com/docs/en/build-with-claude/fast-mode+ ("claude-fable-5-2", adaptiveNoSampling & #supportsForcedToolChoice .~ False & #supportsThinkingDisabled .~ False & #fastModeCost ?~ CatalogCost 16 80 0.4 20) ] where opus55Facts = adaptiveNoSampling & #supportsForcedToolChoice .~ False & #supportsThinkingDisabled .~ False & #fastModeCost ?~ CatalogCost 8 40 0.4 10@@ -440,9 +456,11 @@ -- 2026-09-07: Opus 5 and 4.8 only; cache multipliers stack on fast rates. -- https://platform.claude.com/docs/en/build-with-claude/fast-mode fastAdaptive = adaptiveNoSampling & #fastModeCost ?~ CatalogCost 10 50 1 12.5- adaptiveNoSampling = AnthropicGenerationFacts AnthropicThinkingAdaptive False True True Nothing- adaptiveWithSampling = AnthropicGenerationFacts AnthropicThinkingAdaptive True True True Nothing- budgetWithSampling = AnthropicGenerationFacts AnthropicThinkingBudget True True True Nothing+ adaptiveNoSampling = AnthropicGenerationFacts AnthropicThinkingAdaptive False True True AnthropicPrefillUnsupported Nothing+ adaptiveWithSampling = AnthropicGenerationFacts AnthropicThinkingAdaptive True True True AnthropicPrefillUnsupported Nothing+ -- https://platform.claude.com/docs/en/api/errors#prefill-not-supported+ -- https://platform.claude.com/docs/en/build-with-claude/thinking#response-prefill-and-forced-tool-use+ budgetWithSampling = AnthropicGenerationFacts AnthropicThinkingBudget True True True AnthropicPrefillRequiresThinkingOff Nothing -- | OpenAI curation with a Chat default and explicit Responses overrides. openaiSpec :: ProviderSpec@@ -722,6 +740,12 @@ [ (("anthropic", "claude-opus-5-5"), Model.PricingPolicy [] (Just 8)), (("anthropic", "claude-opus-5"), Model.PricingPolicy [] (Just 10)), (("anthropic", "claude-opus-4-8"), Model.PricingPolicy [] (Just 10)),+ -- 2026-11-20: Standard rates double for input and cache and increase+ -- 1.5x for output when input exceeds 272K.+ -- https://developers.openai.com/api/docs/models/gpt-6.2-astra+ -- https://developers.openai.com/api/docs/models/gpt-6.2-sol+ (("openai", "gpt-6.2-astra"), Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 16 60 0.8 20) (Just 40)] (Just 20)),+ (("openai", "gpt-6.2-sol"), Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 4 15 0.2 5) (Just 10)] (Just 5)), (("openai", "gpt-6-astra"), Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 20 75 2 25) Nothing] Nothing), (("anthropic", "claude-sonnet-5-5"), Model.PricingPolicy [] (Just 4)), (("openai", "gpt-6.1-sol"), Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 4 15 0.2 5) Nothing] Nothing),@@ -731,8 +755,37 @@ -- guide's total 2.5x uncached-input rate (not an added surcharge). (("openai", "gpt-6-luna"), Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 0.2 0.75 0.02 0.25) (Just 0.5)] (Just 0.25)), (("anthropic", "claude-fable-5-1"), Model.PricingPolicy [] (Just 20)),+ -- 2026-11-20: Fable 5.2 has flat rates and a distinct 1h cache-write rate.+ -- https://platform.claude.com/docs/en/about-claude/pricing+ (("anthropic", "claude-fable-5-2"), Model.PricingPolicy [] (Just 16)),+ -- 2026-11-20: Terra doubles input and cache rates and charges 1.5x+ -- output above 272K. The 12h write rate also doubles in that tier.+ -- https://developers.openai.com/api/docs/models/gpt-6.1-terra+ (("openai", "gpt-6.1-terra"), Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 2 7.5 0.1 2.5) (Just 5)] (Just 2.5)),+ -- 2026-11-20: GPT-5.6 uses Sol's prices. These are the active+ -- promotional Sol rates through November 30, 2026. The whole-request+ -- threshold also applies to the Terra and Luna GPT-5.6 models.+ -- https://developers.openai.com/api/docs/models/gpt-5.6-sol+ -- https://developers.openai.com/api/docs/models/gpt-5.6-terra+ -- https://developers.openai.com/api/docs/models/gpt-5.6-luna+ (("openai", "gpt-5.6"), gpt56SolPricing),+ (("openai", "gpt-5.6-sol"), gpt56SolPricing),+ (("openai", "gpt-5.6-terra"), Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 4 18 0.4 5) Nothing] Nothing),+ (("openai", "gpt-5.6-luna"), Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 0.4 1.8 0.04 0.5) Nothing] Nothing),+ -- 2026-11-20: Messages accepts 1h cache writes on these models.+ -- https://platform.claude.com/docs/en/about-claude/pricing#model-pricing+ (("anthropic", "claude-fable-5"), Model.PricingPolicy [] (Just 20)),+ (("anthropic", "claude-haiku-4-5"), Model.PricingPolicy [] (Just 2)),+ (("anthropic", "claude-opus-4-5"), Model.PricingPolicy [] (Just 10)),+ (("anthropic", "claude-opus-4-6"), Model.PricingPolicy [] (Just 10)),+ (("anthropic", "claude-opus-4-7"), Model.PricingPolicy [] (Just 10)),+ (("anthropic", "claude-sonnet-4-5"), Model.PricingPolicy [] (Just 6)),+ (("anthropic", "claude-sonnet-4-6"), Model.PricingPolicy [] (Just 6)),+ (("anthropic", "claude-sonnet-5"), Model.PricingPolicy [] (Just 4)), (("anthropic", "claude-haiku-5-5"), Model.PricingPolicy [Model.InputPriceTier 100000 (Model.ModelCost 0.5 2.5 0.05 0.625) (Just 1)] (Just 0.2)) ]+ where+ gpt56SolPricing = Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 8 30 0.8 10) Nothing] Nothing renderPricingPolicy :: Model.PricingPolicy -> Text renderPricingPolicy p = "{\"inputTiers\": [" <> Text.intercalate ", " (map tier (Model.inputTiers p)) <> "]" <> long policyLong <> "}"@@ -760,7 +813,8 @@ <> ",", " \"supportsFastMode\": " <> jsonBool (maybe False (const True) (facts ^. #fastModeCost)) <> ",", " \"supportsForcedToolChoice\": " <> jsonBool (facts ^. #supportsForcedToolChoice) <> ",",- " \"supportsThinkingDisabled\": " <> jsonBool (facts ^. #supportsThinkingDisabled),+ " \"supportsThinkingDisabled\": " <> jsonBool (facts ^. #supportsThinkingDisabled) <> ",",+ " \"assistantPrefillPolicy\": " <> jsonString (renderPrefillPolicy (facts ^. #assistantPrefillPolicy)), " }," ] renderModelCompat (Just (CatalogOpenAICompat facts)) =@@ -777,16 +831,23 @@ " \"kind\": \"openai-responses\",", " \"supportsSamplingParameters\": " <> jsonBool (facts ^. #supportsSamplingParameters) <> ",", " \"supportsLongCacheRetention\": " <> jsonBool (facts ^. #supportsLongCacheRetention) <> ",",- " \"supportsPromptCacheOptions\": " <> jsonBool (facts ^. #supportsPromptCacheOptions) <> ",",- " \"nativeCachePolicy\": " <> maybe "null" (decodeUtf8 . LBS.toStrict . encode) (facts ^. #nativeCachePolicy) <> ",",- " \"supportedReasoningEfforts\": " <> maybe "null" (\xs -> "[" <> Text.intercalate ", " (map (jsonString . renderThinkingLevel) xs) <> "]") (facts ^. #supportedReasoningEfforts),- " },"+ " \"supportsPromptCacheOptions\": " <> jsonBool (facts ^. #supportsPromptCacheOptions) <> "," ]+ <> [" \"systemPromptInInput\": true," | facts ^. #systemPromptInInput]+ <> [ " \"nativeCachePolicy\": " <> maybe "null" (decodeUtf8 . LBS.toStrict . encode) (facts ^. #nativeCachePolicy) <> ",",+ " \"supportedReasoningEfforts\": " <> maybe "null" (\xs -> "[" <> Text.intercalate ", " (map (jsonString . renderThinkingLevel) xs) <> "]") (facts ^. #supportedReasoningEfforts),+ " },"+ ] -- | The catalog dialect spells the thinking style as a word, as every -- other catalog enum does. The derived JSON instance on -- 'Baikai.Compat.AnthropicThinkingStyle' is part of 'Baikai.Model.Model'\'s -- pinned round trip and is deliberately not reused here.+renderPrefillPolicy :: AnthropicAssistantPrefillPolicy -> Text+renderPrefillPolicy = \case+ AnthropicPrefillUnsupported -> "unsupported"+ AnthropicPrefillRequiresThinkingOff -> "requires-thinking-off"+ renderThinkingStyle :: AnthropicThinkingStyle -> Text renderThinkingStyle AnthropicThinkingBudget = "budget" renderThinkingStyle AnthropicThinkingAdaptive = "adaptive"
gen/GenModelsCore.hs view
@@ -24,8 +24,10 @@ import Baikai.Api (Api (..), parseApi) import Baikai.Compat- ( AnthropicMessagesCompat- ( sendSessionAffinityHeaders,+ ( AnthropicAssistantPrefillPolicy (..),+ AnthropicMessagesCompat+ ( assistantPrefillPolicy,+ sendSessionAffinityHeaders, supportsCacheControlOnTools, supportsFastMode, supportsForcedToolChoice,@@ -130,7 +132,8 @@ long <- o .:? "supportsLongCacheRetention" .!= d.supportsLongCacheRetention native <- o .:? "nativeCachePolicy" modern <- o .:? "supportsPromptCacheOptions" .!= d.supportsPromptCacheOptions- pure d {nativeCachePolicy = native, supportedReasoningEfforts = efforts, supportsSamplingParameters = sampling, supportsLongCacheRetention = long, supportsPromptCacheOptions = modern}+ prefix <- o .:? "systemPromptInInput" .!= d.systemPromptInInput+ pure d {systemPromptInInput = prefix, nativeCachePolicy = native, supportedReasoningEfforts = efforts, supportsSamplingParameters = sampling, supportsLongCacheRetention = long, supportsPromptCacheOptions = modern} parseOpenAICompat :: Aeson.Object -> Parser OpenAICompletionsCompat parseOpenAICompat o = do@@ -176,6 +179,7 @@ fast <- o .:? "supportsFastMode" .!= False forced <- o .:? "supportsForcedToolChoice" .!= d.supportsForcedToolChoice disabled <- o .:? "supportsThinkingDisabled" .!= d.supportsThinkingDisabled+ prefill <- traverse parsePrefillPolicy =<< o .:? "assistantPrefillPolicy" pure d { supportsLongCacheRetention = slcr,@@ -185,9 +189,16 @@ supportsSamplingParameters = ssp, supportsFastMode = fast, supportsForcedToolChoice = forced,- supportsThinkingDisabled = disabled+ supportsThinkingDisabled = disabled,+ assistantPrefillPolicy = prefill } +parsePrefillPolicy :: Text -> Parser AnthropicAssistantPrefillPolicy+parsePrefillPolicy = \case+ "unsupported" -> pure AnthropicPrefillUnsupported+ "requires-thinking-off" -> pure AnthropicPrefillRequiresThinkingOff+ other -> fail ("unknown assistantPrefillPolicy: " <> Text.unpack other)+ -- | The catalog dialect spells the extended-thinking wire shape as a -- word, as every other catalog enum does, rather than through the -- derived instance on 'AnthropicThinkingStyle' (which is part of@@ -497,8 +508,10 @@ "", "import Baikai.Api (Api (..))", "import Baikai.Compat",- " ( AnthropicMessagesCompat",- " ( sendSessionAffinityHeaders,",+ " ( AnthropicAssistantPrefillPolicy (..),",+ " AnthropicMessagesCompat",+ " ( assistantPrefillPolicy,",+ " sendSessionAffinityHeaders,", " supportsCacheControlOnTools,", " supportsFastMode,", " supportsForcedToolChoice,",@@ -693,9 +706,10 @@ " supportsSamplingParameters = " <> renderBool c.supportsSamplingParameters <> ",", " supportsLongCacheRetention = " <> renderBool c.supportsLongCacheRetention <> ",", " supportsPromptCacheOptions = " <> renderBool c.supportsPromptCacheOptions <> ",",- " nativeCachePolicy = " <> renderNativeCache c.nativeCachePolicy,- " }"+ " nativeCachePolicy = " <> renderNativeCache c.nativeCachePolicy <> if c.systemPromptInInput then "," else "" ]+ <> [" systemPromptInInput = True" | c.systemPromptInInput]+ <> [" }"] CatalogCompatAnthropic c -> [ " compat =", " CompatAnthropicMessages",@@ -707,9 +721,10 @@ " supportsSamplingParameters = " <> renderBool c.supportsSamplingParameters <> ",", " supportsFastMode = " <> renderBool c.supportsFastMode <> ",", " supportsForcedToolChoice = " <> renderBool c.supportsForcedToolChoice <> ",",- " supportsThinkingDisabled = " <> renderBool c.supportsThinkingDisabled,- " }"+ " supportsThinkingDisabled = " <> renderBool c.supportsThinkingDisabled <> maybe "" (const ",") c.assistantPrefillPolicy ]+ <> maybe [] (\policy -> [" assistantPrefillPolicy = Just " <> Text.pack (show policy)]) c.assistantPrefillPolicy+ <> [" }"] renderMaxTokensField :: MaxTokensField -> Text renderMaxTokensField = \case
src/Baikai/Compat.hs view
@@ -48,7 +48,7 @@ validateNativeCachePolicy, -- * OpenAI Responses compat- OpenAIResponsesCompat (supportedReasoningEfforts, supportsSamplingParameters, supportsLongCacheRetention, supportsPromptCacheOptions, nativeCachePolicy),+ OpenAIResponsesCompat (supportedReasoningEfforts, supportsSamplingParameters, supportsLongCacheRetention, supportsPromptCacheOptions, systemPromptInInput, nativeCachePolicy), defaultOpenAIResponsesCompat, -- * Anthropic Messages compat@@ -60,8 +60,10 @@ supportsFastMode, supportsForcedToolChoice, supportsThinkingDisabled,- supportsSamplingParameters+ supportsSamplingParameters,+ assistantPrefillPolicy ),+ AnthropicAssistantPrefillPolicy (..), AnthropicThinkingStyle (..), defaultAnthropicMessagesCompat, @@ -248,6 +250,8 @@ supportsLongCacheRetention :: !Bool, -- | Use prompt_cache_options rather than legacy prompt_cache_retention. supportsPromptCacheOptions :: !Bool,+ -- | Put the reusable system prompt at the head of Responses input.+ systemPromptInInput :: !Bool, nativeCachePolicy :: !(Maybe NativeCachePolicy) } deriving stock (Eq, Show, Generic)@@ -260,6 +264,7 @@ supportsSamplingParameters = True, supportsLongCacheRetention = True, supportsPromptCacheOptions = False,+ systemPromptInInput = False, nativeCachePolicy = Nothing } @@ -286,9 +291,17 @@ <*> o .: "supportsSamplingParameters" <*> o .: "supportsLongCacheRetention" <*> o .: "supportsPromptCacheOptions"+ <*> o .:? "systemPromptInInput" .!= False <*> o .:? "nativeCachePolicy" --- | Feature flags for one Anthropic Messages-compatible host.+-- | When Messages rejects a request ending with an assistant turn.+data AnthropicAssistantPrefillPolicy+ = AnthropicPrefillUnsupported+ | AnthropicPrefillRequiresThinkingOff+ deriving stock (Eq, Show, Generic)+ deriving anyclass (FromJSON, ToJSON)++-- | Feature flags for one Anthropic Messages-compatible model or host. data AnthropicMessagesCompat = AnthropicMessagesCompat { -- | Whether the host honours Anthropic's -- @cache_control.ttl: "1h"@ long-retention marker. When 'False',@@ -337,7 +350,9 @@ -- records say so; there @none@ clamps to the lowest adaptive effort -- and the clamp is recorded. Consumed by -- @Baikai.Provider.Claude.Internal.Request.computeThinking@.- supportsThinkingDisabled :: !Bool+ supportsThinkingDisabled :: !Bool,+ -- | A missing policy preserves pass-through for unannotated models.+ assistantPrefillPolicy :: !(Maybe AnthropicAssistantPrefillPolicy) } deriving stock (Eq, Show, Generic) deriving anyclass (ToJSON)@@ -353,7 +368,8 @@ supportsSamplingParameters = True, supportsFastMode = False, supportsForcedToolChoice = True,- supportsThinkingDisabled = False+ supportsThinkingDisabled = False,+ assistantPrefillPolicy = Nothing } -- | Older persisted models predate the fast-mode, forced-choice and@@ -369,6 +385,7 @@ <*> o .:? "supportsFastMode" .!= False <*> o .:? "supportsForcedToolChoice" .!= True <*> o .:? "supportsThinkingDisabled" .!= False+ <*> o .:? "assistantPrefillPolicy" -- | Pick a sensible compat record for an unknown OpenAI-compatible -- host based on its @baseUrl@. Falls back to
src/Baikai/Content.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE LambdaCase #-}+{-# LANGUAGE PatternSynonyms #-} -- | Typed content blocks for user, assistant, and tool-result messages. --@@ -21,12 +22,15 @@ canonicalDataText, ThinkingContent (..), ThinkingReplay (..),+ OutputItemReplay (..), ToolCall (..), ImageContent (..), -- * Per-role block sums UserContent (..),- AssistantContent (..),+ AssistantContent (AssistantText, AssistantThinking, AssistantToolCall, AssistantData),+ outputItemReplay,+ withOutputItemReplay, ToolResultContent (..), -- * Tool-call arguments@@ -144,6 +148,25 @@ instance ToJSON ThinkingReplay where toJSON = genericToJSON snakeOptions +-- | A complete provider text or function-call item paired with its public+-- projection. The consuming adapter validates the scope and the projection+-- before replay. Persist the original item without exposing it through Show.+data OutputItemReplay = OutputItemReplay+ { outputReplayApi :: !Api,+ outputReplayModel :: !Text,+ outputReplayItem :: !Value+ }+ deriving stock (Eq, Generic)++instance Show OutputItemReplay where+ show _ = "OutputItemReplay <opaque>"++instance FromJSON OutputItemReplay where+ parseJSON = genericParseJSON snakeOptions++instance ToJSON OutputItemReplay where+ toJSON = genericToJSON snakeOptions+ -- | A model-issued tool invocation. @id_@ has a trailing underscore in -- Haskell to dodge a clash with @Prelude.id@; the JSON encoding strips -- it back to @id@.@@ -208,12 +231,48 @@ -- | What a provider can put into a 'Baikai.Message.AssistantMessage'. data AssistantContent- = AssistantText !TextContent+ = AssistantTextBlock !TextContent !(Maybe OutputItemReplay) | AssistantThinking !ThinkingContent- | AssistantToolCall !ToolCall+ | AssistantToolCallBlock !ToolCall !(Maybe OutputItemReplay) | AssistantData !DataContent- deriving stock (Eq, Show, Generic)+ deriving stock (Eq, Generic) +pattern AssistantText :: TextContent -> AssistantContent+pattern AssistantText t <- AssistantTextBlock t _+ where+ AssistantText t = AssistantTextBlock t Nothing++pattern AssistantToolCall :: ToolCall -> AssistantContent+pattern AssistantToolCall call <- AssistantToolCallBlock call _+ where+ AssistantToolCall call = AssistantToolCallBlock call Nothing++{-# COMPLETE AssistantText, AssistantThinking, AssistantToolCall, AssistantData #-}++instance Show AssistantContent where+ showsPrec p = \case+ AssistantText t -> field "AssistantText" t+ AssistantThinking t -> field "AssistantThinking" t+ AssistantToolCall call -> field "AssistantToolCall" call+ AssistantData d -> field "AssistantData" d+ where+ field :: (Show a) => String -> a -> ShowS+ field label x = showParen (p > 10) (showString label . showChar ' ' . showsPrec 11 x)++outputItemReplay :: AssistantContent -> Maybe OutputItemReplay+outputItemReplay = \case+ AssistantTextBlock _ state -> state+ AssistantToolCallBlock _ state -> state+ _ -> Nothing++-- | Attach an original output item to its text or tool projection. Thinking+-- uses its own continuation state, and structured data has no output item.+withOutputItemReplay :: OutputItemReplay -> AssistantContent -> AssistantContent+withOutputItemReplay state = \case+ AssistantText t -> AssistantTextBlock t (Just state)+ AssistantToolCall call -> AssistantToolCallBlock call (Just state)+ block -> block+ -- | What a caller can put into a 'Baikai.Message.ToolResultMessage'. data ToolResultContent = ToolResultText !TextContent@@ -309,10 +368,26 @@ toJSON = genericToJSON contentSumOptions instance FromJSON AssistantContent where- parseJSON = genericParseJSON contentSumOptions+ parseJSON = withObject "AssistantContent" $ \o -> do+ kind <- o .: "type"+ case (kind :: Text) of+ "assistant_text" -> AssistantTextBlock <$> o .: "data" <*> o .:? "replay_state"+ "assistant_thinking" -> AssistantThinking <$> o .: "data"+ "assistant_tool_call" -> AssistantToolCallBlock <$> o .: "data" <*> o .:? "replay_state"+ "assistant_data" -> AssistantData <$> o .: "data"+ _ -> fail "Unknown assistant content type" instance ToJSON AssistantContent where- toJSON = genericToJSON contentSumOptions+ toJSON block =+ object $+ fields block <> maybe [] (\state -> ["replay_state" .= state]) (outputItemReplay block)+ where+ fields = \case+ AssistantText t -> tagged "assistant_text" t+ AssistantThinking t -> tagged "assistant_thinking" t+ AssistantToolCall call -> tagged "assistant_tool_call" call+ AssistantData d -> tagged "assistant_data" d+ tagged kind payload = ["type" .= (kind :: Text), "data" .= payload] instance FromJSON ToolResultContent where parseJSON = genericParseJSON contentSumOptions
src/Baikai/Models/Generated.hs view
@@ -8,8 +8,10 @@ import Baikai.Api (Api (..)) import Baikai.Compat- ( AnthropicMessagesCompat- ( sendSessionAffinityHeaders,+ ( AnthropicAssistantPrefillPolicy (..),+ AnthropicMessagesCompat+ ( assistantPrefillPolicy,+ sendSessionAffinityHeaders, supportsCacheControlOnTools, supportsFastMode, supportsForcedToolChoice,@@ -89,7 +91,7 @@ cacheWriteCost = 25 % 2 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [] (Just (20 % 1))), contextWindow = 1000000, maxOutputTokens = 128000, headers = Map.empty,@@ -103,7 +105,8 @@ supportsSamplingParameters = False, supportsFastMode = False, supportsForcedToolChoice = True,- supportsThinkingDisabled = False+ supportsThinkingDisabled = False,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } @@ -140,10 +143,57 @@ supportsSamplingParameters = False, supportsFastMode = False, supportsForcedToolChoice = False,- supportsThinkingDisabled = False+ supportsThinkingDisabled = False,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } +anthropic_claude_fable_5_2 :: Model+anthropic_claude_fable_5_2 =+ emptyModel+ { modelId = "claude-fable-5-2",+ name = "Claude Fable 5.2",+ api = AnthropicMessages,+ provider = "anthropic",+ baseUrl = "https://api.anthropic.com",+ reasoning = True,+ input = [InputText, InputImage],+ outputKind = GenerativeOutput,+ cost =+ ModelCost+ { inputCost = 8 % 1,+ outputCost = 40 % 1,+ cacheReadCost = 1 % 5,+ cacheWriteCost = 10 % 1+ },+ fastModeCost =+ Just+ ( ModelCost+ { inputCost = 16 % 1,+ outputCost = 80 % 1,+ cacheReadCost = 2 % 5,+ cacheWriteCost = 20 % 1+ }+ ),+ pricingPolicy = Just (PricingPolicy [] (Just (16 % 1))),+ contextWindow = 1000000,+ maxOutputTokens = 128000,+ headers = Map.empty,+ compat =+ CompatAnthropicMessages+ defaultAnthropicMessagesCompat+ { supportsLongCacheRetention = True,+ supportsCacheControlOnTools = True,+ sendSessionAffinityHeaders = False,+ thinkingStyle = AnthropicThinkingAdaptive,+ supportsSamplingParameters = False,+ supportsFastMode = True,+ supportsForcedToolChoice = False,+ supportsThinkingDisabled = False,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported+ }+ }+ anthropic_claude_haiku_4_5 :: Model anthropic_claude_haiku_4_5 = emptyModel@@ -163,7 +213,7 @@ cacheWriteCost = 5 % 4 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [] (Just (2 % 1))), contextWindow = 200000, maxOutputTokens = 64000, headers = Map.empty,@@ -177,7 +227,8 @@ supportsSamplingParameters = True, supportsFastMode = False, supportsForcedToolChoice = True,- supportsThinkingDisabled = True+ supportsThinkingDisabled = True,+ assistantPrefillPolicy = Just AnthropicPrefillRequiresThinkingOff } } @@ -214,7 +265,8 @@ supportsSamplingParameters = False, supportsFastMode = False, supportsForcedToolChoice = True,- supportsThinkingDisabled = True+ supportsThinkingDisabled = True,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } @@ -237,7 +289,7 @@ cacheWriteCost = 25 % 4 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [] (Just (10 % 1))), contextWindow = 200000, maxOutputTokens = 64000, headers = Map.empty,@@ -251,7 +303,8 @@ supportsSamplingParameters = True, supportsFastMode = False, supportsForcedToolChoice = True,- supportsThinkingDisabled = True+ supportsThinkingDisabled = True,+ assistantPrefillPolicy = Just AnthropicPrefillRequiresThinkingOff } } @@ -274,7 +327,7 @@ cacheWriteCost = 25 % 4 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [] (Just (10 % 1))), contextWindow = 1000000, maxOutputTokens = 128000, headers = Map.empty,@@ -288,7 +341,8 @@ supportsSamplingParameters = True, supportsFastMode = False, supportsForcedToolChoice = True,- supportsThinkingDisabled = True+ supportsThinkingDisabled = True,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } @@ -311,7 +365,7 @@ cacheWriteCost = 25 % 4 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [] (Just (10 % 1))), contextWindow = 1000000, maxOutputTokens = 128000, headers = Map.empty,@@ -325,7 +379,8 @@ supportsSamplingParameters = False, supportsFastMode = False, supportsForcedToolChoice = True,- supportsThinkingDisabled = True+ supportsThinkingDisabled = True,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } @@ -370,7 +425,8 @@ supportsSamplingParameters = False, supportsFastMode = True, supportsForcedToolChoice = True,- supportsThinkingDisabled = True+ supportsThinkingDisabled = True,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } @@ -415,7 +471,8 @@ supportsSamplingParameters = False, supportsFastMode = True, supportsForcedToolChoice = True,- supportsThinkingDisabled = True+ supportsThinkingDisabled = True,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } @@ -460,7 +517,8 @@ supportsSamplingParameters = False, supportsFastMode = True, supportsForcedToolChoice = False,- supportsThinkingDisabled = False+ supportsThinkingDisabled = False,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } @@ -483,7 +541,7 @@ cacheWriteCost = 15 % 4 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [] (Just (6 % 1))), contextWindow = 200000, maxOutputTokens = 64000, headers = Map.empty,@@ -497,7 +555,8 @@ supportsSamplingParameters = True, supportsFastMode = False, supportsForcedToolChoice = True,- supportsThinkingDisabled = True+ supportsThinkingDisabled = True,+ assistantPrefillPolicy = Just AnthropicPrefillRequiresThinkingOff } } @@ -520,7 +579,7 @@ cacheWriteCost = 15 % 4 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [] (Just (6 % 1))), contextWindow = 1000000, maxOutputTokens = 128000, headers = Map.empty,@@ -534,7 +593,8 @@ supportsSamplingParameters = True, supportsFastMode = False, supportsForcedToolChoice = True,- supportsThinkingDisabled = True+ supportsThinkingDisabled = True,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } @@ -557,7 +617,7 @@ cacheWriteCost = 5 % 2 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [] (Just (4 % 1))), contextWindow = 1000000, maxOutputTokens = 128000, headers = Map.empty,@@ -571,7 +631,8 @@ supportsSamplingParameters = False, supportsFastMode = False, supportsForcedToolChoice = True,- supportsThinkingDisabled = True+ supportsThinkingDisabled = True,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } @@ -608,7 +669,8 @@ supportsSamplingParameters = False, supportsFastMode = False, supportsForcedToolChoice = False,- supportsThinkingDisabled = False+ supportsThinkingDisabled = False,+ assistantPrefillPolicy = Just AnthropicPrefillUnsupported } } @@ -1037,7 +1099,7 @@ cacheWriteCost = 5 % 1 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [InputPriceTier 272000 (ModelCost (8 % 1) (30 % 1) (4 % 5) (10 % 1)) Nothing] Nothing), contextWindow = 1050000, maxOutputTokens = 128000, headers = Map.empty,@@ -1077,7 +1139,7 @@ cacheWriteCost = 1 % 4 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [InputPriceTier 272000 (ModelCost (2 % 5) (9 % 5) (1 % 25) (1 % 2)) Nothing] Nothing), contextWindow = 1050000, maxOutputTokens = 128000, headers = Map.empty,@@ -1103,7 +1165,7 @@ cacheWriteCost = 5 % 1 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [InputPriceTier 272000 (ModelCost (8 % 1) (30 % 1) (4 % 5) (10 % 1)) Nothing] Nothing), contextWindow = 1050000, maxOutputTokens = 128000, headers = Map.empty,@@ -1129,7 +1191,7 @@ cacheWriteCost = 5 % 2 }, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (PricingPolicy [InputPriceTier 272000 (ModelCost (4 % 1) (18 % 1) (2 % 5) (5 % 1)) Nothing] Nothing), contextWindow = 1050000, maxOutputTokens = 128000, headers = Map.empty,@@ -1250,6 +1312,110 @@ } } +openai_gpt_6_1_terra :: Model+openai_gpt_6_1_terra =+ emptyModel+ { modelId = "gpt-6.1-terra",+ name = "GPT-6.1 Terra",+ api = OpenAIResponses,+ provider = "openai",+ baseUrl = "https://api.openai.com",+ reasoning = True,+ input = [InputText, InputImage],+ outputKind = GenerativeOutput,+ cost =+ ModelCost+ { inputCost = 1 % 1,+ outputCost = 5 % 1,+ cacheReadCost = 1 % 20,+ cacheWriteCost = 5 % 4+ },+ fastModeCost = Nothing,+ pricingPolicy = Just (PricingPolicy [InputPriceTier 272000 (ModelCost (2 % 1) (15 % 2) (1 % 10) (5 % 2)) (Just (5 % 1))] (Just (5 % 2))),+ contextWindow = 1050000,+ maxOutputTokens = 128000,+ headers = Map.empty,+ compat =+ CompatOpenAIResponses+ defaultOpenAIResponsesCompat+ { supportedReasoningEfforts = Just [ThinkingNone, ThinkingLow, ThinkingMedium, ThinkingHigh, ThinkingXHigh, ThinkingMax],+ supportsSamplingParameters = False,+ supportsLongCacheRetention = True,+ supportsPromptCacheOptions = True,+ nativeCachePolicy = Just (NativeCacheModern True True)+ }+ }++openai_gpt_6_2_astra :: Model+openai_gpt_6_2_astra =+ emptyModel+ { modelId = "gpt-6.2-astra",+ name = "GPT-6.2 Astra",+ api = OpenAIResponses,+ provider = "openai",+ baseUrl = "https://api.openai.com",+ reasoning = True,+ input = [InputText, InputImage],+ outputKind = GenerativeOutput,+ cost =+ ModelCost+ { inputCost = 8 % 1,+ outputCost = 40 % 1,+ cacheReadCost = 2 % 5,+ cacheWriteCost = 10 % 1+ },+ fastModeCost = Nothing,+ pricingPolicy = Just (PricingPolicy [InputPriceTier 272000 (ModelCost (16 % 1) (60 % 1) (4 % 5) (20 % 1)) (Just (40 % 1))] (Just (20 % 1))),+ contextWindow = 1050000,+ maxOutputTokens = 128000,+ headers = Map.empty,+ compat =+ CompatOpenAIResponses+ defaultOpenAIResponsesCompat+ { supportedReasoningEfforts = Just [ThinkingLow, ThinkingMedium, ThinkingHigh, ThinkingXHigh, ThinkingMax],+ supportsSamplingParameters = False,+ supportsLongCacheRetention = True,+ supportsPromptCacheOptions = True,+ nativeCachePolicy = Just (NativeCacheModern True True),+ systemPromptInInput = True+ }+ }++openai_gpt_6_2_sol :: Model+openai_gpt_6_2_sol =+ emptyModel+ { modelId = "gpt-6.2-sol",+ name = "GPT-6.2 Sol",+ api = OpenAIResponses,+ provider = "openai",+ baseUrl = "https://api.openai.com",+ reasoning = True,+ input = [InputText, InputImage],+ outputKind = GenerativeOutput,+ cost =+ ModelCost+ { inputCost = 2 % 1,+ outputCost = 10 % 1,+ cacheReadCost = 1 % 10,+ cacheWriteCost = 5 % 2+ },+ fastModeCost = Nothing,+ pricingPolicy = Just (PricingPolicy [InputPriceTier 272000 (ModelCost (4 % 1) (15 % 1) (1 % 5) (5 % 1)) (Just (10 % 1))] (Just (5 % 1))),+ contextWindow = 1050000,+ maxOutputTokens = 128000,+ headers = Map.empty,+ compat =+ CompatOpenAIResponses+ defaultOpenAIResponsesCompat+ { supportedReasoningEfforts = Just [ThinkingLow, ThinkingMedium, ThinkingHigh, ThinkingXHigh, ThinkingMax],+ supportsSamplingParameters = False,+ supportsLongCacheRetention = True,+ supportsPromptCacheOptions = True,+ nativeCachePolicy = Just (NativeCacheModern True True),+ systemPromptInInput = True+ }+ }+ openai_gpt_6_astra :: Model openai_gpt_6_astra = emptyModel@@ -1621,6 +1787,7 @@ allModels = [ anthropic_claude_fable_5, anthropic_claude_fable_5_1,+ anthropic_claude_fable_5_2, anthropic_claude_haiku_4_5, anthropic_claude_haiku_5_5, anthropic_claude_opus_4_5,@@ -1654,6 +1821,9 @@ openai_gpt_5_mini, openai_gpt_5_nano, openai_gpt_6_1_sol,+ openai_gpt_6_1_terra,+ openai_gpt_6_2_astra,+ openai_gpt_6_2_sol, openai_gpt_6_astra, openai_gpt_6_luna, openai_gpt_6_sol,
test/CatalogSpec.hs view
@@ -22,9 +22,11 @@ import Baikai.Api (Api (AnthropicMessages, OpenAIResponses)) import Baikai.Compat- ( AnthropicMessagesCompat,+ ( AnthropicAssistantPrefillPolicy (..),+ AnthropicMessagesCompat, AnthropicThinkingStyle (..), OpenAIResponsesCompat (supportedReasoningEfforts, supportsLongCacheRetention, supportsPromptCacheOptions, supportsSamplingParameters),+ assistantPrefillPolicy, supportsFastMode, supportsForcedToolChoice, supportsSamplingParameters,@@ -73,19 +75,19 @@ c.supportsSamplingParameters @?= False c.supportedReasoningEfforts @?= Just [ThinkingLow, ThinkingMedium, ThinkingHigh, ThinkingXHigh, ThinkingMax] _ -> assertFailure "Astra needs explicit OpenAI endpoint facts",- testCase "Sol, Luna, and GPT-6.1 Sol select Responses with explicit endpoint facts" $+ testCase "Sol, Luna, and Terra select Responses with explicit endpoint facts" $ mapM_ ( \mid -> do [api m | m <- allModels, modelId m == mid] @?= [OpenAIResponses] case [compat m | m <- allModels, modelId m == mid] of [CompatOpenAIResponses c] -> do c.supportsPromptCacheOptions @?= True- c.supportsLongCacheRetention @?= (mid == "gpt-6-luna")+ c.supportsLongCacheRetention @?= (mid `elem` ["gpt-6-luna", "gpt-6.1-terra"]) c.supportsSamplingParameters @?= False c.supportedReasoningEfforts @?= Just ([ThinkingNone | mid /= "gpt-6.1-sol"] <> [ThinkingLow, ThinkingMedium, ThinkingHigh, ThinkingXHigh, ThinkingMax])- _ -> assertFailure "GPT-6 Sol/Luna need explicit OpenAI Responses facts"+ _ -> assertFailure "model needs explicit OpenAI Responses facts" )- ["gpt-6-sol", "gpt-6-luna", "gpt-6.1-sol"],+ ["gpt-6-sol", "gpt-6-luna", "gpt-6.1-sol", "gpt-6.1-terra"], testCase "regenerating from data/models produces no diff" $ withSystemTempDirectory "baikai-catalog-spec" $ \tmpDir -> do let regenPath = tmpDir <> "/Generated.hs"@@ -119,22 +121,23 @@ -- | The shipped thinking style, sampling, forced-choice, fast-mode and -- disabled-thinking support of each Anthropic catalog id, written out by -- hand from @baikai\/data\/models\/anthropic.json@.-expectedAnthropicFacts :: [(Text, (AnthropicThinkingStyle, Bool, Bool, Bool, Bool))]+expectedAnthropicFacts :: [(Text, (AnthropicThinkingStyle, Bool, Bool, Bool, Bool, Maybe AnthropicAssistantPrefillPolicy))] expectedAnthropicFacts =- [ ("claude-fable-5", (AnthropicThinkingAdaptive, False, True, False, False)),- ("claude-fable-5-1", (AnthropicThinkingAdaptive, False, False, False, False)),- ("claude-haiku-4-5", (AnthropicThinkingBudget, True, True, False, True)),- ("claude-haiku-5-5", (AnthropicThinkingAdaptive, False, True, False, True)),- ("claude-opus-4-5", (AnthropicThinkingBudget, True, True, False, True)),- ("claude-opus-4-6", (AnthropicThinkingAdaptive, True, True, False, True)),- ("claude-opus-4-7", (AnthropicThinkingAdaptive, False, True, False, True)),- ("claude-opus-4-8", (AnthropicThinkingAdaptive, False, True, True, True)),- ("claude-opus-5", (AnthropicThinkingAdaptive, False, True, True, True)),- ("claude-opus-5-5", (AnthropicThinkingAdaptive, False, False, True, False)),- ("claude-sonnet-4-5", (AnthropicThinkingBudget, True, True, False, True)),- ("claude-sonnet-4-6", (AnthropicThinkingAdaptive, True, True, False, True)),- ("claude-sonnet-5", (AnthropicThinkingAdaptive, False, True, False, True)),- ("claude-sonnet-5-5", (AnthropicThinkingAdaptive, False, False, False, False))+ [ ("claude-fable-5", (AnthropicThinkingAdaptive, False, True, False, False, Just AnthropicPrefillUnsupported)),+ ("claude-fable-5-1", (AnthropicThinkingAdaptive, False, False, False, False, Just AnthropicPrefillUnsupported)),+ ("claude-fable-5-2", (AnthropicThinkingAdaptive, False, False, True, False, Just AnthropicPrefillUnsupported)),+ ("claude-haiku-4-5", (AnthropicThinkingBudget, True, True, False, True, Just AnthropicPrefillRequiresThinkingOff)),+ ("claude-haiku-5-5", (AnthropicThinkingAdaptive, False, True, False, True, Just AnthropicPrefillUnsupported)),+ ("claude-opus-4-5", (AnthropicThinkingBudget, True, True, False, True, Just AnthropicPrefillRequiresThinkingOff)),+ ("claude-opus-4-6", (AnthropicThinkingAdaptive, True, True, False, True, Just AnthropicPrefillUnsupported)),+ ("claude-opus-4-7", (AnthropicThinkingAdaptive, False, True, False, True, Just AnthropicPrefillUnsupported)),+ ("claude-opus-4-8", (AnthropicThinkingAdaptive, False, True, True, True, Just AnthropicPrefillUnsupported)),+ ("claude-opus-5", (AnthropicThinkingAdaptive, False, True, True, True, Just AnthropicPrefillUnsupported)),+ ("claude-opus-5-5", (AnthropicThinkingAdaptive, False, False, True, False, Just AnthropicPrefillUnsupported)),+ ("claude-sonnet-4-5", (AnthropicThinkingBudget, True, True, False, True, Just AnthropicPrefillRequiresThinkingOff)),+ ("claude-sonnet-4-6", (AnthropicThinkingAdaptive, True, True, False, True, Just AnthropicPrefillUnsupported)),+ ("claude-sonnet-5", (AnthropicThinkingAdaptive, False, True, False, True, Just AnthropicPrefillUnsupported)),+ ("claude-sonnet-5-5", (AnthropicThinkingAdaptive, False, False, False, False, Just AnthropicPrefillUnsupported)) ] assertFacts :: Model -> IO ()@@ -152,5 +155,5 @@ <> show other ) where- facts :: AnthropicMessagesCompat -> (AnthropicThinkingStyle, Bool, Bool, Bool, Bool)- facts c = (thinkingStyle c, c.supportsSamplingParameters, c.supportsForcedToolChoice, c.supportsFastMode, c.supportsThinkingDisabled)+ facts :: AnthropicMessagesCompat -> (AnthropicThinkingStyle, Bool, Bool, Bool, Bool, Maybe AnthropicAssistantPrefillPolicy)+ facts c = (thinkingStyle c, c.supportsSamplingParameters, c.supportsForcedToolChoice, c.supportsFastMode, c.supportsThinkingDisabled, c.assistantPrefillPolicy)
test/EmbeddingSpec.hs view
@@ -20,6 +20,7 @@ ) import Baikai.Error (BaikaiError, ErrorCategory (..), decodeError) import Baikai.Http qualified as Http+import Control.Concurrent.MVar (MVar, newMVar, withMVar) import Control.Exception qualified as Exception import Control.Lens ((&), (.~), (^.)) import Data.Generics.Labels ()@@ -31,11 +32,14 @@ import Servant.Client qualified as Client import System.Environment (lookupEnv) import System.Environment qualified as Environment-import Test.Tasty (TestTree, testGroup)+import Test.Tasty (TestTree, testGroup, withResource) import Test.Tasty.HUnit (assertBool, assertFailure, testCase, (@?=)) tests :: TestTree-tests =+tests = withResource (newMVar ()) (const (pure ())) embeddingTests++embeddingTests :: IO (MVar ()) -> TestTree+embeddingTests getKeyLock = testGroup "Baikai.Embedding" [ testCase "mkEmbeddingRequest maps input, model id, and dimensions" $ do@@ -58,7 +62,7 @@ -- The defect: whatever the base URL said, the default key was -- OPENAI_API_KEY. Pointing an EmbeddingModel at DeepSeek sent an -- OpenAI key to DeepSeek.- withEnv "OPENAI_API_KEY" (Just "openai-secret") $+ withFixtureKey $ withEnv "DEEPSEEK_API_KEY" Nothing $ do err <- expectAuthError@@ -67,7 +71,7 @@ ("names the host's own variable: " <> Text.unpack (err ^. #message)) ("DEEPSEEK_API_KEY" `Text.isInfixOf` (err ^. #message)), testCase "an unknown embedding host refuses rather than sending OpenAI's key" $- withEnv "OPENAI_API_KEY" (Just "openai-secret") $ do+ withFixtureKey $ do err <- expectAuthError (emptyEmbeddingModel & #baseUrl .~ "https://vectors.example")@@ -75,18 +79,18 @@ ("says what to set: " <> Text.unpack (err ^. #message)) ("EmbeddingModel.apiKey" `Text.isInfixOf` (err ^. #message)), testCase "the OpenAI default still resolves OPENAI_API_KEY" $- withEnv "OPENAI_API_KEY" (Just "openai-secret") $ do+ withFixtureKey $ do resolved <- resolveEmbeddingKey (openAIEmbeddingModel "text-embedding-3-small")- resolved @?= "openai-secret",+ assertBool "selected the fixture API key" (resolved == "openai-secret"), testCase "an explicit key source wins over the per-host table" $- withEnv "OPENAI_API_KEY" (Just "openai-secret") $ do+ withFixtureKey $ do resolved <- resolveEmbeddingKey ( openAIEmbeddingModel "m" & #apiKey .~ Just (ApiKeyLiteral "explicit-key") )- resolved @?= "explicit-key",+ assertBool "selected the explicit API key" (resolved == "explicit-key"), testCase "embeddings share the connection cache with the chat providers" $ do -- One TLS manager per host, not one per call: the SDK's own -- getClientEnv allocated a fresh manager every time embed ran.@@ -106,17 +110,25 @@ live <- lookupEnv "BAIKAI_EMBEDDING_LIVE" case live of Just "1" -> do- v <- embedOne (openAIEmbeddingModel "text-embedding-3-small") "hello"- V.length v @?= 1536+ lock <- getKeyLock+ withMVar lock $ \() -> do+ v <- embedOne (openAIEmbeddingModel "text-embedding-3-small") "hello"+ V.length v @?= 1536 _ -> putStrLn "BAIKAI_EMBEDDING_LIVE not set; skipping live test" ]+ where+ withFixtureKey action = do+ lock <- getKeyLock+ withMVar lock $ \() ->+ withEnv "OPENAI_KEY" Nothing $+ withEnv "OPENAI_API_KEY" (Just "openai-secret") action -- | Resolve a model's key, expecting it to refuse. expectAuthError :: EmbeddingModel -> IO BaikaiError expectAuthError m = do thrown <- Exception.try (resolveEmbeddingKey m) :: IO (Either BaikaiError Text) case thrown of- Right key -> assertFailure ("expected an AuthError, got a key: " <> Text.unpack key)+ Right _ -> assertFailure "expected an AuthError, got a key" Left err -> do err ^. #category @?= AuthError pure err
test/FetchModelsSpec.hs view
@@ -6,7 +6,7 @@ -- models.dev-shaped fixture. No network is involved. module FetchModelsSpec (tests) where -import Baikai.Compat (AnthropicThinkingStyle (..), defaultOpenAICompletionsCompat, defaultOpenAIResponsesCompat)+import Baikai.Compat (AnthropicAssistantPrefillPolicy (..), AnthropicThinkingStyle (..), defaultOpenAICompletionsCompat, defaultOpenAIResponsesCompat) import Baikai.Compat qualified as C import Baikai.Model (InputModality (..)) import Baikai.Model qualified@@ -108,7 +108,7 @@ outputKind = Baikai.Model.GenerativeOutput, cost = CatalogCost 5 25 1.5 6.25, fastModeCost = Nothing,- pricingPolicy = Nothing,+ pricingPolicy = Just (Model.PricingPolicy [] (Just 10)), contextWindow = 200000, maxOutputTokens = 64000, apiOverride = Nothing,@@ -120,6 +120,7 @@ supportsSamplingParameters = True, supportsForcedToolChoice = True, supportsThinkingDisabled = True,+ assistantPrefillPolicy = AnthropicPrefillRequiresThinkingOff, fastModeCost = Nothing } )@@ -198,6 +199,7 @@ let refreshed = normalizeProvider anthropicSpec (Map.singleton mid (sample & #modelId .~ mid)) expected | mid == "claude-opus-5-5" = Just (CatalogCost 8 40 0.4 10)+ | mid == "claude-fable-5-2" = Just (CatalogCost 16 80 0.4 20) | mid `elem` ["claude-opus-5", "claude-opus-4-8"] = Just (CatalogCost 10 50 1 12.5) | otherwise = Nothing map (^. #fastModeCost) (refreshed ^. #models) @?= [expected]@@ -212,6 +214,7 @@ (openaiSpec, "gpt-6-sol", Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 4 15 0.4 5) Nothing] Nothing), (openaiSpec, "gpt-6-luna", Model.PricingPolicy [Model.InputPriceTier 272000 (Model.ModelCost 0.2 0.75 0.02 0.25) (Just 0.5)] (Just 0.25)), (anthropicSpec, "claude-fable-5-1", Model.PricingPolicy [] (Just 20)),+ (anthropicSpec, "claude-fable-5-2", Model.PricingPolicy [] (Just 16)), (anthropicSpec, "claude-opus-5-5", Model.PricingPolicy [] (Just 8)) ] $ \(spec, mid, policy) -> do@@ -312,7 +315,8 @@ " \"supportsSamplingParameters\": true,", " \"supportsFastMode\": false,", " \"supportsForcedToolChoice\": true,",- " \"supportsThinkingDisabled\": true",+ " \"supportsThinkingDisabled\": true,",+ " \"assistantPrefillPolicy\": \"requires-thinking-off\"", " }," ] `Text.isInfixOf` rendered
test/PricingPolicySpec.hs view
@@ -29,6 +29,14 @@ let u = U.zeroUsage & #inputTokens .~ (n - 2000) & #cacheReadTokens .~ 1000 & #cacheWriteTokens .~ 1000 & #outputTokens .~ 100 resolveRates Nothing m u @?= Right expected (computeCost m u).usd @?= (fromIntegral (n - 2000) * expected.inputCost + 1000 * expected.cacheReadCost + 1000 * expected.cacheWriteCost + 100 * expected.outputCost) / 1000000,+ testCase "GPT-6.1 Terra selects the published cache duration and prompt-length rates" $ do+ let m = Models.openai_gpt_6_1_terra+ atThreshold = U.zeroUsage & #inputTokens .~ 270000 & #cacheReadTokens .~ 1000 & #cacheWriteTokens .~ 1000+ aboveThreshold = atThreshold & #cacheWriteTokens .~ 1001+ resolveRates (Just CacheRetentionShort) m atThreshold @?= Right (M.ModelCost 1 5 (1 / 20) (5 / 4))+ resolveRates (Just CacheRetentionLong) m atThreshold @?= Right (M.ModelCost 1 5 (1 / 20) (5 / 2))+ resolveRates (Just CacheRetentionShort) m aboveThreshold @?= Right (M.ModelCost 2 (15 / 2) (1 / 10) (5 / 2))+ resolveRates (Just CacheRetentionLong) m aboveThreshold @?= Right (M.ModelCost 2 (15 / 2) (1 / 10) 5), testCase "Opus 5.5 prices short, long, and observed fast cache writes" $ do let m = Models.anthropic_claude_opus_5_5 u = U.zeroUsage & #cacheWriteTokens .~ 1000000@@ -101,6 +109,17 @@ (computeCost fable (U.zeroUsage & #cacheReadTokens .~ 1000)).usd @?= 1 / 4000 (computeCostWith (Just CacheRetentionShort) fable (U.zeroUsage & #cacheWriteTokens .~ 1000)).usd @?= 1 / 80 (computeCostWith (Just CacheRetentionLong) fable (U.zeroUsage & #cacheWriteTokens .~ 1000)).usd @?= 1 / 50,+ testCase "Fable 5.2 has flat rates with separate short, long, and observed fast cache prices" $ do+ let m = Models.anthropic_claude_fable_5_2+ writes = U.zeroUsage & #cacheWriteTokens .~ 1000+ observed speed = U.observeBilling [U.BillingServiceTier "standard", U.BillingSpeed speed] writes+ resolveRates (Just CacheRetentionShort) m (U.zeroUsage & #inputTokens .~ 999000) @?= Right (M.ModelCost 8 40 (1 / 5) 10)+ m.fastModeCost @?= Just (M.ModelCost 16 80 (2 / 5) 20)+ forM_ [(CacheRetentionShort, 1 / 100, 1 / 50), (CacheRetentionLong, 2 / 125, 4 / 125)] $ \(duration, standard, fast) -> do+ let price speed = computeCostForService (Just duration) Nothing m (observed speed)+ (price "standard").usd @?= standard+ (price "fast").usd @?= fast+ (price "fast").basis.estimateReasons @?= Set.empty, testCase "reasoning is a subset of output, not an extra charge" $ do let u = U.zeroUsage & #outputTokens .~ 100 computeCost astra (u & #reasoningTokens .~ Just 75) @?= computeCost astra u,