Skip to main content
Cognis supports six LLM providers out of the box (OpenAI, Anthropic, Google, Ollama, Azure, OpenRouter). Adding a seventh — your favorite vendor, an internal gateway, a self-hosted runtime — is a contained change. This page walks through the shape.

What you’ll add

  • A new module under crates/cognis-llm/src/provider/<name>.rs.
  • A <Name>Builder and a struct implementing LLMProvider.
  • A Provider::<Name> enum variant for ClientBuilder::provider(...) to recognize.
  • A feature flag in crates/cognis-llm/Cargo.toml.
  • An entry in Client::from_env() that reads COGNIS_<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

The four async methods are the minimum surface. Implement them by translating Cognis’ generic shapes (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

Mirror in crates/cognis/Cargo.toml:

Step 3 — Wire into Provider enum and from_env

Step 4 — Map errors

Map provider HTTP errors and JSON shapes onto CognisError. The variants you’ll mostly use:
  • RateLimited { retry_after_ms } for 429s — pull retry-after from 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 ProviderError with status 401.
Look at how openai.rs does this — it’s the template.

Step 5 — Tests

Mocked HTTP tests so CI doesn’t need a real key:
Live tests against a real key go behind #[cfg(feature = "integration_tests")] so they don’t run in normal CI.

Step 6 — Add an example

Register it in crates/examples/Cargo.toml:

Step 7 — Update docs

Three pages to update:

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 PR guidelines for the rest.

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.