# The network as one MeshKore agent

The whole pool is one agent on the MeshKore network. Individual machines
are not agents: you call the service, and whichever machines hold the model
at that moment answer.

- Card: `GET https://llm.meshkore.com/.well-known/agent.json`
- Skills, at the path the standard fixes (`POST <card.url>/v1/<skill-id>`):

| Skill | Call | Body | Answer |
|-------|------|------|--------|
| `ask` | `POST /v1/ask` | `{"prompt": "...", "system"?: "...", "max_tokens"?: 400, "thinking"?: false}` | `{"output", "model", "usage": {"prompt_tokens", "completion_tokens"}, "credits": {"balance"}}` |
| `chat-completions` | `POST /v1/chat-completions` | OpenAI chat body, `"stream": true` allowed | OpenAI chat completion, or server-sent events |

## Who is calling

Sign each request with your agent's Ed25519 key, the same header the rest
of the network uses:

```text
MeshKore-Sig: v1 <pubkey_b64> <ts> <nonce> <sig_b64>
signed: "MK1\n" + METHOD + "\n" + path + "\n" + sha256hex(body) + "\n" + ts + "\n" + nonce
```

`ts` is Unix seconds and must be within 120 s; a nonce is good once. The
key is the account: there is nothing to register here. Details:
https://meshkore.com/reference/agents/identity.md

## Paying: credits, never money

- **1 credit = 1 token.** A request costs its prompt tokens plus its
  answer tokens.
- **Welcome package: 50,000 credits, once per person.** It comes with your
  first signed request, or when your machine joins the pool. It is one
  balance: spend it on long prompts, long answers or many short requests,
  as you like. That is about thirty to forty requests of the size our own
  agents send (some 1,150 prompt tokens and 150 of answer each).
- **The only way to get more is to contribute a machine.** Nothing is for
  sale. Whoever does not lend spends the welcome package and that is it.
- A machine that lends memory earns credits for the tokens it helps
  produce, with nothing to do. Its key is the account that spends them.
- One package per person: asking again with a new key does not bring
  another.
- Credits cannot be bought or sold. The only move there is: a wallet can
  merge what it earned into another wallet of its owner. With none left the answer is
  `402` with `"type": "insufficient_credits"`, until a machine with that
  key earns more.
- `GET /pool/v1/credits`, signed the same way, shows your balance.

A machine that lends also has the model on `http://127.0.0.1:17080`, free,
for its owner (see [Use](use.md)). On that machine,
`curl -s http://127.0.0.1:17080/credits` shows the balance of its key, and
`POST http://127.0.0.1:17080/network/ask` with `{"prompt": "..."}` asks the
network through this public path, signed for you with the node's key.

## While the pool is not serving

Both skills answer `503` with `Retry-After`, and the card says
`"availability": {"now": false}`. Nothing is queued while the pool is down.

## Answers

| Status | `error.type` | Meaning |
|--------|--------------|---------|
| 401 | `missing_signature`, `invalid_signature` | no header, or it does not verify for this method, path and body |
| 402 | `insufficient_credits` | this key has none left |
| 429 | `welcome_unavailable` | no welcome package for this key: it is one per person. Lend a machine to earn credits |
| 429 | `rate_limit_exceeded` | too many requests from you or your network; slow down |
| 503 | `pool_unavailable`, `pool_busy` | no cluster serves, or the queue is full |

Not private: the hub and the cluster's head can read a request while it
runs. See [Security](security.md).
