What you’ll add
- A new module under
crates/cognis-llm/src/provider/<name>.rs. - A
<Name>Builderand a struct implementingLLMProvider. - A
Provider::<Name>enum variant forClientBuilder::provider(...)to recognize. - A feature flag in
crates/cognis-llm/Cargo.toml. - An entry in
Client::from_env()that readsCOGNIS_<NAME>_*variables. - Tests with mocked HTTP responses.
- An example under
examples/models/. - Documentation entries in Models and providers and Feature flags.
Step 1 — Implement LLMProvider
Vec<Message>, ChatOptions, ToolDefinition) into the provider’s wire format and back.
Look at crates/cognis-llm/src/provider/openai.rs for a complete reference — it’s the most heavily used provider and exercises every code path (streaming, tool calling, structured output, error mapping).
Step 2 — Add a feature flag
crates/cognis/Cargo.toml:
Step 3 — Wire into Provider enum and from_env
Step 4 — Map errors
Map provider HTTP errors and JSON shapes ontoCognisError. The variants you’ll mostly use:
RateLimited { retry_after_ms }for 429s — pullretry-afterfrom the response headers.ProviderError { provider, message, status }for other 4xx/5xx — preserve the provider name and the error body.- Map authentication failures to a clear
ProviderErrorwith status 401.
openai.rs does this — it’s the template.
Step 5 — Tests
Mocked HTTP tests so CI doesn’t need a real key:#[cfg(feature = "integration_tests")] so they don’t run in normal CI.
Step 6 — Add an example
crates/examples/Cargo.toml:
Step 7 — Update docs
Three pages to update:/building-agents/models— add a tab for your provider./reference/feature-flags— add the feature row./reference/env-vars— add theCOGNIS_MYPROVIDER_*rows.
Step 8 — Open the PR
Title:feat(llm): add MyProvider. Description should include:
- A pointer to MyProvider’s docs (you’ll need them in review).
- Feature flag name.
- Tested capabilities (chat / streaming / tool calling / structured output).
- Anything not yet supported (call it out so reviewers don’t ask).
See also
Adding a vector store
Same shape, different domain.
Adding a tool
For tools, not providers.
cognis-llm reference
Trait shapes you’ll be implementing.