Menu ▾ ▴

#6 Add `anthropic` provider to `orko-providers` crate

open
nobody
2026-08-11
2026-08-11
Anonymous
No

Originally created by: SAMAD101

Summary

Add an anthropic provider to orko-providers. Anthropic's Messages API is not OpenAI-compatible on the wire, so unlike [#4]/#5 this is a second codec, not a preset. It reuses the transport trait from [#3] unchanged — the codec is pure computation and can be built and unit-tested in parallel with [#3] (only integration needs the transport).

Wire details

  • Endpoint: POST https://api.anthropic.com/v1/messages (base URL configurable)
  • Headers: x-api-key: $ANTHROPIC_API_KEY (conventional env key), anthropic-version: 2023-06-01, content-type: application/json
  • max_tokens is required — needs a sane default in the preset, overridable via CompletionOptions

Codec mapping (orko-core ↔ Messages API)

Request side:

  • System messages are a top-level system param, not a message role — the codec lifts them out of the transcript
  • Tool definitions use input_schema (vs OpenAI's nested function.parameters) — straight rename from orko_core::Tool::schema()
  • Assistant tool calls are tool_use content blocks; tool results go back as tool_result blocks inside a user message — codec translates orko-core's message shape to this and back
  • Content parts: text → text blocks; images → {"type": "image", "source": {...}} where source is {type: "base64", media_type, data} or {type: "url", url} — maps 1:1 onto orko_core::MediaSource

Response/streaming side (SSE):

  • Event sequence: message_start → content_block_start → content_block_delta* → content_block_stop (per block) → message_delta → message_stop
  • text_delta deltas → text chunks; input_json_delta deltas carry partial_json for tool arguments — the content-block index + concatenated partial JSON maps directly onto orko_core::ToolCallDelta (tool id/name arrive in the block's content_block_start)
  • message_delta carries stop_reason + usage → map to orko_core::FinishReason / Usage (end_turn, tool_use, max_tokens, refusal, …)
  • Tolerate unknown event types / fields (serde default) — Anthropic adds event kinds over time

Preset + parsing

  • anthropic(model) constructor; fallible from_str("anthropic:claude-opus-5")
  • Quirks struct entry documenting: required max_tokens, system lifting, no OpenAI compat

Acceptance

  • Codec unit tests, no network: request JSON snapshots (system lifting, tool defs, tool_result round-trip, image parts) and a checked-in SSE fixture → chunk assertions incl. a streamed tool call reassembled through the invoke loop's delta grouping
  • clippy -D warnings clean; builds with --no-default-features (codec only)
  • Workspace rules hold: no tokio in public signatures; deps flow down to orko-core only

Shares the transport trait from [#3]; codec work itself has no dependency on it.

Related

Tickets: #15
Tickets: #23
Tickets: #3
Tickets: #4

Discussion


Log in to post a comment.