Repository navigation
Conversation
Adds a second configured-provider protocol so fx can talk directly to
the Anthropic Messages API (or any compatible endpoint) from
~/.fx/settings.json:
"providers": {
"claude": {
"protocol": "anthropic-messages",
"base_url": "https://api.anthropic.com/v1",
"auth": { "type": "x-api-key", "env": "ANTHROPIC_API_KEY" },
"model_metadata": { "claude-sonnet-4-5": { ... } }
}
}
- configured_provider: protocol gains the anthropic-messages variant;
auth gains x-api-key; endpoint_url routes /messages vs /chat/completions
- anthropic_messages_protocol: request serialization (system hoist,
tool_use/tool_result blocks, inline images, thinking budgets from
reasoning effort) and SSE reduction (message_start/content_block_*/
message_delta), with verbatim thinking-block replay bound to the
tool calls it was minted beside
- anthropic_messages: transport bundle mirroring chat_completions
(endpoint, headers, catalog projection, reviewer plumbing)
- wire-name projection: Anthropic tool names forbid dots, so dotted fx
tool identities map to [A-Za-z0-9_-] wire names inbound and outbound
- credentials: x-api-key env credentials resolve like bearer
Adds an Anthropic Messages SSE fixture and two cases to configured-providers.test.ts: x-api-key auth + /v1/messages request shape (system hoist, stream flag, content parts), and a tool_use / tool_result round trip asserting signed thinking blocks replay verbatim on the continuation request.
Addresses codec review findings that would 400 or misbehave on the wire: - Skip thinking on required tool calls (tool_choice:any is rejected alongside thinking); required calls keep their contract. - Omit thinking when max_tokens cannot exceed the budget floor. - Serialize parallel_tool_calls=false as disable_parallel_tool_use, forcing an explicit tool_choice when the mode would omit it. - Map model_context_window_exceeded to a length finish reason. - Bound signature deltas by the replay budget instead of identity_bytes. - Free owned tool calls on the OOM path in Reducer.finish.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an
anthropic-messagesProtocolvariant to the configured-provider architecture so~/.fx/settings.jsonconnections can talk directly to the Anthropic Messages API — the direct-vendor-key gap tracked in #150.{ "providers": { "claude": { "protocol": "anthropic-messages", "base_url": "https://api.anthropic.com", "auth": { "type": "x-api-key", "env": "ANTHROPIC_API_KEY" }, "model_metadata": { "claude-sonnet-4-5": { "context_window": 200000, "max_output_tokens": 8192 } } } } }configured_provider.Protocolgains@"anthropic-messages"andAuthgainsx_api_key;builtins/providers.zigdispatches to a newanthropic_messagestransport that mirrorschat_completions(SSE stream, prepared-body reuse, deadline enforcement), sendingx-api-key+anthropic-version: 2023-06-01instead of bearer auth.The codec (
anthropic_messages_protocol.zig) handles the wire differences: hoists instructions into thesystemstring, emits content-part arrays, projects dotted tool names onto Anthropic's[A-Za-z0-9_-]namespace viawire_name(functions.read→functions_read), reducesmessage_start/content_block_*/message_deltaSSE events intostream_provider.Result, and binds thinking blocks to tool calls inprovider_state_jsonso signed thinking replays verbatim (Anthropic rejects mismatched signatures when tool use continues).budget_tokensis clamped belowmax_tokens, thinking is skipped ontool_choice:anycalls (rejected together),parallel_tool_calls:falseserializes asdisable_parallel_tool_use, andmodel_context_window_exceededmaps to.length.E2E coverage in
configured-providers.test.tsdrives the built binary against a local SSE fixture: request shape +x-api-keyheaders on/v1/messages, and a tool_use→tool_result round trip asserting signed thinking replay on the continuation.