Files
docs/guides/api-access.md
inference-bot 2047b0e98f accounting copy: credits share the same pool as the allowance
API access, local chat apps and models pages described spending as "the
monthly allowance" only. Credit packs apply to chat and API alike, so say the
pool is allowance + credits; troubleshooting and cost sentences match the
implemented two-bucket model.
2026-11-27 22:06:26 +00:00

154 lines
6.2 KiB
Markdown

# API access
Members can use the co-op's models programmatically through an OpenAI-compatible
API. It's the same infrastructure that powers the chat — any OpenAI-compatible
client works.
## Quick facts
- **Base URL:** `https://gateway.inference.coop/v1`
- **Auth:** a bearer API key (create one in the [Member Dashboard](https://dashboard.inference.coop))
- **Format:** OpenAI chat completions — `POST https://gateway.inference.coop/v1/chat/completions`
- **Models:** see the [model list](models.md).
- **Not only chat:** the gateway also serves a decision endpoint,
`POST https://gateway.inference.coop/v1/systemone` — see
[Decisions](models.md#decisions). It takes a different request shape, so
it is not reachable through an OpenAI SDK's `chat.completions` call.
API usage draws from the **same monthly allowance as chat**, and credit packs
apply to both — there's no separate quota.
## What the co-op stores about your requests
Usage records, and nothing else: the model, token counts, cost, and which key made
the request — that is how your monthly metering works. **Your prompts and the
responses are not stored on our side.** The API path keeps no conversation, so there
is no transcript to delete later.
Two things worth being precise about:
- The **chat interface** is different — it saves your conversations so you can revisit
them. If you want the API's behaviour there instead, use a **temporary chat**.
- The **provider** is a separate question. Whether a model's operator retains anything
is set by that provider, not by us, and it varies by model — the
[model list](models.md) distinguishes policy-based zero retention from
enclave-based protection.
Full detail, including what we can and cannot see:
[What happens with your data](what-happens-with-your-data.md) and the
[privacy policy](../governance/privacy-policy.md).
## Get a key
Log in to the [Member Dashboard](https://dashboard.inference.coop)) and create an
API key. The key is an `sk-…` string you pass as a bearer token.
## Plain `curl`
```bash
curl https://gateway.inference.coop/v1/chat/completions \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{"model": "tinfoil/deepseek-v4-1-flash", "messages": [{"role": "user", "content": "Hello"}]}'
```
## OpenAI SDK (Python, Node, etc.)
Point the SDK at our base URL and use your member key:
```python
from openai import OpenAI
client = OpenAI(
base_url="https://gateway.inference.coop/v1",
api_key="sk-your-key",
)
resp = client.chat.completions.create(
model="tinfoil/deepseek-v4-1-flash",
messages=[{"role": "user", "content": "Hello"}],
)
```
Any OpenAI-compatible client works the same way: set the base URL to
`https://gateway.inference.coop/v1` and the API key to your member key.
## Decisions (Metis)
Alongside the chat models, the gateway exposes GreenPT's **Metis** decision model
at `POST https://gateway.inference.coop/v1/systemone`. It is the same key and the
same base URL — only the path and the request body differ. For what it is, the
three question types, and a full `curl` example, see
[Decisions in the model list](models.md#decisions).
Two practical notes:
- **It is not an OpenAI chat endpoint.** You send a `state` plus typed `questions`
and receive probabilities; there is nothing for an OpenAI SDK's
`chat.completions` to parse. Post the body directly (`curl`, `requests`,
`httpx`, or an SDK's generic POST).
- **Its usage is metered like any other call.** Each decision is billed at
**$0.12 per 1M input tokens**, figured from the exact token count GreenPT
returns (Metis generates no prose, so there is no output cost). Decisions draw
on the same monthly allowance as chat.
## Coding agents and other OpenAI-compatible clients
Any tool that speaks the OpenAI API works. Where a tool asks for provider or
endpoint configuration:
- **Base URL / endpoint:** `https://gateway.inference.coop/v1`
- **API type / protocol:** "OpenAI compatible" (or `openai-completions` where a
protocol string must be named) — not "Ollama", "Anthropic", or "Responses"
- **API key:** your member key (the `sk-…` string)
- **Model:** a **stable alias** — `deepseek-flash-green`, `glm-flash-green`, `deepseek-flash-tee`, or `glm-tee`
— or any id from the [model list](models.md), e.g. `tinfoil/deepseek-v4-1-flash`
A typical provider entry looks like:
```json
{
"providers": {
"inference-coop": {
"baseUrl": "https://gateway.inference.coop/v1",
"api": "openai-completions",
"apiKey": "sk-your-key",
"models": [
{ "id": "deepseek-flash-green" },
{ "id": "glm-flash-green" },
{ "id": "deepseek-flash-tee" },
{ "id": "glm-tee" }
]
}
}
}
```
The four names in `models` are **stable aliases**: we re-point them when a
provider retires or replaces a model, so a config that pins one keeps working
across transitions. The suffix says which route: `-green` is the default
(renewable energy, policy-based privacy), `-tee` serves the same family inside
attested hardware. Each alias is paired, so the two routes sit side by side in the
model list.
Pricing is set at the alias, so a transition that changes price appears in the
model list rather than arriving as a surprise. If you need one particular version,
use the provider-prefixed id from the [model list](models.md) instead.
Where the aliases point today:
| Alias | Serves today | Route |
| --- | --- | --- |
| `deepseek-flash-green` | `greenpt/deepseek-v4.1-flash` | Renewable energy; policy-based privacy |
| `glm-flash-green` | `greenpt/glm-5.3-flash` | Renewable energy; policy-based privacy |
| `deepseek-flash-tee` | `tinfoil/deepseek-v4-1-flash` | Confidential computing (TEE) |
| `glm-tee` | `tinfoil/glm-5.3` | Confidential computing (TEE) |
*Points as of 2026-11-14. We re-point these when a provider retires or replaces a
model; the alias names stay as they are, and this table changes with them.*
If a tool's own docs show a local-server example (e.g.
`baseUrl: http://localhost:11434/v1` with `api: "openai-completions"`),
substitute our base URL and your member key for `apiKey` — the protocol value
stays the same. Some tools append `/chat/completions` to the base URL themselves;
if your base URL already ends in `/v1`, that's correct and you should not add
`/chat/completions`.