flutter_ai_provider_anthropic 0.1.12
flutter_ai_provider_anthropic: ^0.1.12 copied to clipboard
Anthropic (Claude) LlmProvider for flutter_ai: streams the Messages API (text, extended thinking, tool use) as flutter_ai_core AiStreamEvents.
Changelog #
0.1.12 #
- Fix:
reasoningEffortnow emits adaptive thinking ({type: adaptive}) on Claude 4.6+ models — including the defaultclaude-opus-4-8, which rejects the legacybudget_tokensshape with a 400. Claude 3.7 and 4.0–4.5 continue to use the budgeted shape. An explicitthinkingblock inextrastill takes precedence. - Fix: a mid-stream
errorevent (e.g.overloaded_error) is no longer overwritten by a synthetic successful finish — the message now settles as errored. - Fix: setting both
responseFormatandreasoningEffortno longer sends an invalid forced-tool-choice-plus-thinking request (a guaranteed 400). Thinking is dropped when structured output is requested.
0.1.11 #
- Map
AiRequestOptions.reasoningEffortto extended thinking (thinking.budget_tokens): raisesmax_tokensabove the budget when needed and dropstemperature(the API rejects both together). An explicitthinkingblock inextratakes precedence. Requiresflutter_ai_core^0.1.13.
0.1.10 #
- Fix (Web): the default HTTP client now streams token-by-token on Flutter Web.
http.Client()resolves to the XHR-backedBrowserClienton the web, which buffers the entire response body before the stream emits — silently degrading streaming to all-at-once. The default is now afetch-based client (via a conditional import) that reads the responseReadableStreamincrementally. Native platforms are unchanged. Inject your ownclientto override.
0.1.9 #
- Fix: raise the
flutter_ai_corelower bound to^0.1.11— the parser emitsAiUsage(added in core 0.1.3) and later APIs, so the old^0.1.0bound let dependency downgrades resolve a core that couldn't compile. - Docs: shortened the pubspec
descriptioninto pub.dev's 60–180 character window.
0.1.8 #
- Docs: refreshed the README listing with a hero image, screenshot gallery, and badges (consistent across the package family). No code changes.
0.1.7 #
- Cost accuracy:
cache_creation_input_tokensnow map toAiUsage.cacheCreationTokens(billed at the ~1.25x write rate) instead of being folded into base input and billed wrong. - Declares supported
platforms:(all 6).
0.1.6 #
- Throws typed
LlmExceptions (auth/rate-limit/server/request) on HTTP errors instead of a genericException; retries 408/409 too.
0.1.5 #
- Replays signed
thinkingblocks beforetool_usein the assistant turn, so extended thinking + tools no longer 400 on Claude 4.x. - A mid-stream stall surfaces a message-scoped
StreamErrorEventinstead of also finalizing (which masked the timeout). - Asserts a non-empty
apiKeywith an actionable message.
0.1.4 #
- Prompt caching: when
AiRequestOptions.cachePromptis set, marks the system prompt and the last tool withcache_control: ephemeral(caches the stable prefix for ~90% cheaper repeat input).
0.1.3 #
- Structured output: maps
AiRequestOptions.responseFormatto a forced tool whose input is the schema; its streamed input is surfaced as the JSON answer text and the turn finishes asstop.
0.1.2 #
- Reports token usage: accumulates input (incl. cache read/creation) from
message_startand output frommessage_deltaintoAiUsageonMessageFinished.
0.1.1 #
- Docs: added a "Buy me a coffee" (Ko-fi) support section to the README. No code changes.
0.1.0 #
Initial release.
AnthropicProvider— anLlmProviderfor the Anthropic Messages API (POST /v1/messages), with an injectable HTTP client, a configurable default model (claude-opus-4-8) andmax_tokens.- Maps conversations into the request: system messages fold into the top-level
systemfield, assistant tool calls becometool_useblocks, and tool results becometool_resultblocks. Streams text, extended thinking, tool calls, and finish reasons back asAiStreamEvents. AnthropicEventParser— the SSE-event→event mapping, unit-tested against recorded events.- Robustness: configurable connect + idle
timeout(a stalled stream surfaces aStreamErrorEventinstead of hanging); a wrong-shape event emits aStreamErrorEventinstead of crashing the stream;close()only closes a client it created; retry backoff is now capped and jittered; adjacent same-role turns are merged so the API's strict alternation isn't violated. - Re-exports
flutter_ai_core.
The mapping is unit-tested against recorded SSE events; it has not been run against the live Anthropic API in this release.