Provider protocols
octo speaks three wire formats. Provider quirks are encapsulated entirely in
internal/provider/{anthropic,openai,responses}/ — the agent layer never branches on which
protocol it’s talking to. Named vendors pin their protocol (the one exception is OpenAI, below); a
Custom endpoint picks one with protocol: openai | anthropic | openai-responses.
Anthropic Messages
Section titled “Anthropic Messages”- Auth via
x-api-key+anthropic-versionheaders. systemis a top-level field, not a message.- Content blocks:
[{type: "text", text}]. - The SSE aggregator dispatches on
message_start/content_block_delta/message_delta. - Tool calls land as a
content_block_startof typetool_use, followed byinput_json_deltafragments that accumulate into the final arguments. stop_reason: "tool_use"is the agent-facing signal that a turn wants to call a tool.
OpenAI Chat Completions
Section titled “OpenAI Chat Completions”- Auth via
Authorization: Bearer. systemis carried asmessages[0], not a separate field.- The SSE aggregator parses
chat.completion.chunkobjects, and tolerates a missing[DONE]sentinel — some third-party OpenAI-compatible servers omit it. - Tool calls arrive in
delta.tool_calls[], chunked bytool_calls[i].index; the aggregator concatenates fragments by index before parsing the JSON arguments. finish_reason: "tool_calls"is normalized to"tool_use"on the agent-facing surface, so the agent loop only ever sees one spelling regardless of backend.stream_options.include_usage: trueis sent on every streaming request — DashScope (Bailian) and real OpenAI emit no usage chunk at all without it, so a streamed turn would otherwise report zero tokens. DeepSeek sends usage either way.
OpenAI Responses
Section titled “OpenAI Responses”POST /v1/responses, auth viaAuthorization: Bearer. Custom endpoints choose it withprotocol: openai-responses, and the OpenAI vendor uses it whenever its base URL isapi.openai.comitself: from GPT-5.4 on, Chat Completions rejects function tools unlessreasoning_effortisnone. An OpenAI vendor pointed at another base URL (OPENAI_BASE_URL, a proxy) keeps Chat Completions; every other named vendor does too.- Every request is stateless (
store: false): the full history is sent each turn. systemgoes in the top-levelinstructionsfield.- Function tools are flat (
{type: "function", name, parameters, strict: false}), not nested underfunction.strictis sent asfalsebecause omitting it makes the API try to rewrite the schema into strict mode. - Tool calls and results are standalone input items (
function_call/function_call_output). - There is no finish reason:
status: "incomplete"withmax_output_tokensmaps to the agent’smax_tokens, and anyfunction_callin the output makes it atool_useturn. - The stream is dispatched on each event’s
type. A function call’scall_idand name arrive only onresponse.output_item.added; the argument deltas after it carry just the item id. - Reasoning models return opaque reasoning items. They are kept in history as
thinkingblocks that carry the item id, the encrypted content and the model that produced them, and are sent back only to that same model. Anything the request can’t be sure the backend accepts is dropped instead, and the Anthropic adapter drops these blocks too.
Cache token accounting
Section titled “Cache token accounting”Cache semantics differ by protocol, not by vendor:
- Anthropic-protocol endpoints (real Anthropic, and Anthropic-compatible gateways) report
input_tokensas the uncached remainder, withcache_read_input_tokensreported separately. - OpenAI-protocol endpoints (DeepSeek’s default endpoint, DashScope) report
prompt_tokensas the whole input, withcached_tokensas a subset of it. - Responses endpoints report
input_tokensas the whole input, withcached_tokensandcache_write_tokensinside it.
The agent treats input tokens and cache-read tokens as non-overlapping buckets — context occupancy is their sum — so the OpenAI and Responses adapters subtract the cached parts before handing counts to the agent layer; the Anthropic adapter needs no adjustment.
Extended reasoning
Section titled “Extended reasoning”Anthropic thinking blocks and OpenAI reasoning_content are unified behind
--reasoning-effort / --show-reasoning: OpenAI-protocol backends receive the effort level
directly as reasoning_effort (reasoning.effort on Responses); Anthropic-protocol backends map it to adaptive thinking or an
explicit token budget, normalized per model family so older models and newer ones both get a
sensible mapping from the same five-level scale.
Next: adding another protocol, or a new tool, follows the pattern in Extending octo.