Inference providers¶
Spongram needs one OpenAI-compatible endpoint for chat completions and embeddings. This page explains how every model call is routed, what the endpoint must support, how to configure and test a provider at run time, and how the reasoning setting, the retries and the circuit breaker behave when the provider misbehaves.
How calls are routed¶
No component calls the provider directly. Graphiti, the Sleeper and the distillation route all
send their requests to an inference proxy inside the spongram service:
The proxy authenticates the caller with SPONGRAM_INTERNAL_AUTH_TOKEN, replaces the model
field with the model configured for the role, replaces the Authorization header with the
provider key, and forwards the request to <base URL>/chat/completions or
<base URL>/embeddings. The configuration is read on every request, so a change takes effect on
the next call without restarting any container.
| Role | Used by | Model setting | What the model must support |
|---|---|---|---|
graphiti |
Extraction of entities and facts from each memory | Graphiti model | Structured output with response_format: {"type": "json_schema", "strict": true}, and OpenAI-style tool_calls |
sleeper |
Background summaries | Sleeper model | Plain text. Speed matters more than size |
distill |
POST /v1/memory/distill (out-of-band capture) |
Graphiti model | Strict json_schema, which is why it does not use the Sleeper model |
any role, /embeddings |
Vectors for entities, facts and queries | Embedder model | A fixed dimension for the life of the deployment |
The Dream worker runs graph queries and schedules work for the Sleeper; it makes no model call of its own.
No external LLM traffic
Memory operations sending no text to an LLM you did not choose is a product requirement. The single proxy enforces it: Graphiti is configured to reach nothing else, and its image refuses to start if its base URL is not the proxy. Whether text leaves your network then depends only on the provider you configure: a model server on your own hosts keeps everything inside; a hosted API receives the text of every memory.
The default endpoint¶
A new server deployment is seeded with:
| Setting | Default |
|---|---|
| Provider | spt-models |
| Base URL | https://models.sponge-theory.dev/v1 |
| Graphiti model | gemma-4-26b-a4b-it |
| Sleeper model | qwen3.5-9b |
| Embedder | jina-embeddings-v5-text-small, 1024 dimensions |
SPONGRAM_INFERENCE_API_KEY supplies the key until one is saved from the admin UI.
A customer installation of the Cloud control plane
(SPONGRAM_CLOUD_CUSTOMER_INSTALLATION=true) has no default: the provider reads unconfigured
and the proxy answers 503 until an administrator configures one.
Configure at run time¶
The settings live in the Postgres table spongram_runtime_config and are edited on the
Settings page of the Admin UI, or through the API:
| Route | Purpose |
|---|---|
GET /admin/api/spongram/settings/inference |
Current configuration. The key is never returned, only api_key_set |
PUT /admin/api/spongram/settings/inference |
Update any subset of the fields |
POST /admin/api/spongram/settings/inference/test |
Probe a candidate configuration without saving it |
GET /admin/api/spongram/settings/inference/providers |
The preset catalogue |
| Field | Stored as | Notes |
|---|---|---|
provider |
inference.provider |
Preset slug |
base_url |
inference.base_url |
OpenAI-compatible base URL, ending in /v1 for most servers |
api_key |
inference.api_key |
Encrypted with SPONGRAM_ENCRYPTION_KEY. Send an empty string to clear it, omit the field to keep it |
graphiti_model, sleeper_model, embedder_model |
inference.graphiti_model, … |
Model names as your endpoint knows them |
embedder_dim |
inference.embedder_dim |
See The embedding dimension is immutable |
sleeper_max_per_tick |
inference.sleeper_max_per_tick |
1 to 200 |
sleeper_interval_sec |
inference.sleeper_interval_sec |
30 to 3600 |
Presets¶
| Slug | Label | Preset base URL |
|---|---|---|
spt-models |
SPT Models (Sponge Theory) | https://models.sponge-theory.dev/v1 |
ollama |
Ollama (local workstation) | http://host.docker.internal:11434/v1 |
lm-studio |
LM Studio (local desktop) | http://host.docker.internal:1234/v1 |
vllm |
vLLM (local GPU server) | http://host.docker.internal:8000/v1 |
openai |
OpenAI (cloud) | https://api.openai.com/v1 |
anthropic |
Anthropic Claude (cloud, via adapter) | https://api.anthropic.com/v1 |
mistral |
Mistral (cloud) | https://api.mistral.ai/v1 |
groq |
Groq (cloud, ultra-fast) | https://api.groq.com/openai/v1 |
litellm |
LiteLLM (inference proxy) | http://host.docker.internal:4000/v1 |
custom |
Custom (any OpenAI-compat endpoint) | empty |
Points that apply whatever the preset:
- One base URL serves chat and embeddings. A provider that offers no embedding model, or an
API that is not OpenAI-compatible, needs a gateway in front that exposes both under one URL.
The
anthropicpreset assumes such an adapter. localhostinside a container is the container. To reach a model server on the Docker host, usehost.docker.internal; on Linux addhost.docker.internal:host-gatewayto theextra_hostsof thespongramservice.- The provider slug changes what is sent. For
spt-modelsandvllmthe proxy sends the vLLM extensionschat_template_kwargsandguided_json. For every other slug it removes them, because strict OpenAI-compatible servers reject unknown arguments with a 400. A vLLM server configured ascustomtherefore does not receive the reasoning setting described below. - vLLM needs tool calling and guided decoding enabled on its command line
(
--enable-auto-tool-choice, a--tool-call-parsersuited to the model, and a guided-decoding backend) for the Graphiti role to work.
Test before saving¶
The connection test runs three probes against the candidate base URL, key and model:
- Plain chat. Proves the URL, the key and the model name.
- Tool calling. Sends a small
toolspayload and checks thattool_callscome back with valid JSON arguments. - Strict
json_schema. Sends an entity-extraction schema of the shape Graphiti uses and parses the result.
If the first fails, the URL or the key is wrong. If the second or third fails, do not use that model for the Graphiti role: memories would be accepted and queued, extraction would fail, and the graph would stay empty. The test does not call the embeddings endpoint; check embeddings by writing a memory to a test brain and searching for it.
The embedding dimension is immutable¶
The graph stores vectors of one dimension. Changing the embedder, or its dimension, makes every stored vector unusable for search.
PUT …/settings/inferencerefuses such a change with 409 and the errorembedder_change_requires_purgeunless the request carries"purge_acknowledged": true.- The acknowledgement purges nothing. You must purge every brain and ingest its content again (see Backup and restore for export, purge and import).
- Each instance records its dimension when it is created (
SPONGRAM_EMBEDDING_DIM, default 1024). A brain export can only be imported into an instance of the same dimension. - The shipped Graphiti image declares
dimensions: 1024in its baked configuration. The reference configuration is a 1024-dimension embedder; plan on that dimension unless you have rebuilt and tested the image with another value.
Choose the embedder before the first memory is written.
Reasoning ("thinking") mode¶
Some model servers expose a reasoning phase that runs before the answer. Spongram decides it in one place, the proxy, per role:
| Variable | Applies to |
|---|---|
SPONGRAM_THINKING_GRAPHITI |
Every call of the graphiti role |
SPONGRAM_THINKING_SLEEPER |
Every call of the sleeper role |
SPONGRAM_THINKING_DISTILL |
Every call of the distill role |
SPONGRAM_THINKING_GRAPHITI_ENTITIES |
Only the Graphiti call whose response schema is named ExtractedEntities |
Values are off (the default for every role), low, medium and xhigh. The proxy writes
the decision into chat_template_kwargs (enable_thinking, and reasoning_effort when on),
overriding whatever the caller set.
- The setting is applied only to chat calls and only for the providers
spt-modelsandvllm. - An invalid value is not sent upstream. For a role, a warning is logged and the role runs with reasoning off. For the per-call variable, a warning is logged and the call follows its role.
- Reasoning makes each call several times slower. Graphiti makes ten to twenty calls per
memory, so turning it on for the whole
graphitirole multiplies the extraction time of every memory.
The per-call setting for entity extraction¶
ExtractedEntities is the one call per memory that decides whether the text contains anything
to extract. With a reasoning-capable model served with reasoning off, that call can return an
empty list for a text that does name entities; the memory is then stored as an episode with no
entity and no fact, and searching for its content finds nothing.
If you observe that with your model, set SPONGRAM_THINKING_GRAPHITI_ENTITIES=low. It enables
reasoning for that single call and leaves the other Graphiti calls unchanged. The costs:
- extraction of each memory takes noticeably longer;
- reasoning tokens are counted with the output tokens of the call;
- a delete issued while a memory of the same brain is being written is more often answered "nothing was deleted, retry" (see Troubleshooting).
Leave it empty for a model that does not have the problem: the call then follows the role.
The service logs the levels in force at start, and one line per call that uses the per-call setting:
thinking levels: graphiti=off (ExtractedEntities=low), sleeper=off, distill=off
thinking[graphiti/ExtractedEntities]: low
These lines are the only evidence that the setting is applied. A redeploy that drops the
variable turns it off without any error. In the Swarm stack file the variable belongs in the
environment: of spongram, not in the anchor shared with graphiti-mcp.
Timeouts, retries and the circuit breaker¶
Read timeouts¶
A non-streaming call waits up to SPONGRAM_REMOTE_READ_TIMEOUT_SEC (600 s) for a remote
provider, and up to SPONGRAM_LOCAL_READ_TIMEOUT_SEC (1800 s) when the base URL contains
localhost or 127.0.0.1, because a local model server may hold the connection silent for the
whole generation.
Retries¶
With SPONGRAM_INFERENCE_RETRY_ENABLED (on by default) the proxy retries a request when the
provider answers 429, 502, 503 or 504, refuses the connection, times out while connecting, or
breaks the protocol. These are the answers of a server that is loading or swapping a model.
Delays start at 2 seconds and double up to 30 seconds, with jitter, inside a total budget of
SPONGRAM_INFERENCE_RETRY_BUDGET_SEC (120 s; 60 s for a loopback provider).
A read timeout is never retried: the model is still working, and a second request would double its load.
Circuit breaker¶
Two breakers protect the provider, one for chat completions and one for embeddings:
| State | Behaviour |
|---|---|
| Closed | Calls pass. SPONGRAM_BREAKER_FAILURE_THRESHOLD (5) consecutive failures open the breaker |
| Open | The proxy answers 503 with error type upstream_breaker_open without calling the provider, for SPONGRAM_BREAKER_COOLDOWN_SEC (60 s) |
| Half-open | One probe request is let through. Success closes the breaker; failure doubles the cool-down, up to SPONGRAM_BREAKER_MAX_COOLDOWN_SEC (600 s) |
A request that was retried counts as a single failure. While the chat breaker is open the
Sleeper skips its ticks and reports the state throttled, which /healthz treats as healthy
(see Observability).
What happens to memories meanwhile¶
Nothing is lost. A memory accepted by add_memory stays in the durable queue; a failed attempt
schedules the next one after 30 seconds, 2 minutes, 10 minutes, 30 minutes, 1 hour, and then
every 6 hours, indefinitely. See Ingestion.
Oversized prompts¶
Graphiti builds some prompts from accumulated graph state. A chat prompt longer than
SPONGRAM_PROMPT_GUARD_MAX_CHARS (64 000 characters) is trimmed by the proxy before it is sent,
and a warning is logged, so that the provider does not reject it for exceeding its context
window. Raise the value if your model has a larger context window.
A per-request key with LiteLLM¶
With the litellm provider on a server, a caller can supply the key that pays for
its own inference:
Authorization still decides which brain is accessed; litellm-api-key only replaces the key
sent to the gateway for the inference of that operation. The caller cannot change the gateway
URL or the brain. The key is encrypted with SPONGRAM_ENCRYPTION_KEY, which must be set
explicitly for this feature, and kept with the queued memory so that a retry after a restart
uses the same key. It is never written into the episode or the graph. Background work (Sleeper,
Dream) always uses the deployment key.
Both images must support it: the proxy answers 503 to Graphiti calls if the Graphiti image does not announce the capability.