Core speaks only the neutral form: the request loop, the journal and the transform layer know a
reply as pic_reply (src/pic.h), with its native form kept verbatim beside it. Everything about a
wire API is a bundled component, an adapter, that registers itself with core through
pic_provider_adapter (src/provider_http.h). The keel note says why.
What an adapter declares
| Field | What it is |
|---|---|
api, name |
the pic_api it serves (src/models.h) and the wire name replies record, as pic_api_name gives it |
open |
makes a pic_provider for a resolved model: reply, summarize, count (NULL when the API has no counter), free |
cache_long_seconds |
how long a long-retention prompt cache lives for a model; NULL means an hour |
norm_id |
a foreign tool-call id as this API takes it; NULL is the default, [A-Za-z0-9_-] and at most 64 |
shapes, nshapes |
the pic_content_shapes its request SQL names in pic_content |
probe |
reserved for checking a key without spending a request; leave NULL |
Core decides what is not the API's: short retention is 300 seconds and none is 0
(pic_cache_seconds), the shapes pi and pi-images are core's own, and refusals go through
the credential seam (pic_cred_health_ops, src/keyhealth.c), which keys its rows by provider, not
by API.
open streams through pic_stream_post with a pic_stream_decoder and fills the reply: native
(what the API sent, replayed only to the same provider, API and model), neutral (Pi's content
array), Pi's stop reason, the raw usage, and provider, api and model. Requests are built in
SQL over PIC_CONTEXT_CTE; a foreign turn is rebuilt from the neutral form with
pic_norm_id(id, NAME, provider), so a tool result's id is rewritten exactly as its call's.
A content shape names a form (PIC_SHAPE_BLOCKS, _BLOCKS_OR_TEXT, _TEXT, _AFTER,
_TEXT_IMAGES), whether it is a tool result (which placeholder an omitted image becomes), which
text to skip, the text block's type, and a function that writes one image block. Shape names are
unique across adapters; prefix them with the adapter's (chat-user, chat-tool).
Adding one
- Write the decoder (
src/NAME.cand.h): SSE events in, one message out, pure over a SQLite connection, assrc/anthropic.cis. Add a directory of recorded streams with their.wantsummaries undertest/pic/, and a mode for it totest/pic/decode_stream.canddecode.sh. - Write the adapter (
src/provider_NAME.c):openand its provider functions, the shapes, andconst pic_provider_adapter pic_NAME_adapter, declared in the decoder's header with a forwardstruct pic_provider_adapter. Its statics need names no other file uses (make test-amal). - If the API is new to the registry, add it to
pic_api,pic_api_nameand the models file's names insrc/models.c. - Register it in
main()insrc/main.c, beside the others. - Add both files to
PIC_SRCin the Makefile and give each a row inci/tiers.tsv(bundled, seamprovider, clockvendor), then regenerate the table in tiers. - Test it against
build/pic/fake_serverastest/pic/chat.shdoes.
test/pic/test_adapter.c registers a toy adapter through the interface alone: it is the smallest
working example. Core with no adapter registered still runs; a model whose API has none fails to
open with "no adapter in this build speaks its API", and the scripted provider
(src/provider_fake.c) needs none, since its replies are neutral already.