# API reference

Page: https://galatea.co/api/docs/reference

Every endpoint, request field and error code of the public API.

The base URL is https://api.galatea.co/v1. Every route takes a bearer key in the Authorization header.

[Download the OpenAPI 3 document (JSON) for every route and error code](https://galatea.co/api/docs/openapi.json)

## Endpoints

### POST /v1/chat/completions

Chat completion. Set stream to true for server-sent events, false for one JSON answer.

- Request field: model
- Request field: galatea_allow_hosted
- Request field: galatea_select_hosted
- Request field: messages
- Request field: stream
- Request field: stream_options
- Request field: max_tokens
- Request field: max_completion_tokens
- Request field: temperature
- Request field: top_p
- Request field: top_k
- Request field: n
- Request field: stop
- Request field: seed
- Request field: presence_penalty
- Request field: frequency_penalty
- Request field: tools
- Request field: tool_choice
- Request field: response_format
- Request field: user
- Request field: reasoning_effort
- Request field: thinking

- Response: 200 chat.completion, or text/event-stream chunks when stream is true

### POST /v1/completions

Text completion from a prompt, for code that predates chat.

- Request field: model
- Request field: galatea_allow_hosted
- Request field: galatea_select_hosted
- Request field: prompt
- Request field: max_tokens
- Request field: temperature
- Request field: top_p
- Request field: top_k
- Request field: stop
- Request field: seed
- Request field: presence_penalty
- Request field: frequency_penalty
- Request field: stream
- Request field: stream_options
- Request field: n
- Request field: echo
- Request field: suffix
- Request field: best_of
- Request field: user

- Response: 200 text_completion, or text/event-stream chunks when stream is true

### GET /v1/models

The models the platform serves, with each one's context window, price and availability. Needs no key.

- Response: 200 list of model objects

### GET /v1/models/{id}

One model by id, for example deepseek-v4.1-flash, in the same shape the list carries. Needs no key.

- Response: 200 model object

### GET /v1/key

The key in the Authorization header, answering about itself: its own spending cap and what is left under it, its usage over its life and for the day, the week and the month, the window its cap resets on, and the request ceiling that governs it. The organization's balance is beside those figures under organization, so nothing reads it as the key's.

- Response: 200 key object

### GET /v1/keys

Every key of the caller's organization, newest first, each with the spend in its own reset window and what is left under its cap. Needs a key with the keys:write scope: this is the management surface, so a key can rotate itself and mint a teammate's key without a browser.

- Response: 200 list of key objects

### POST /v1/keys

Mint a key of the caller's organization. The secret is in this one answer and never again: only its hash and visible prefix are stored. Needs a management key holding keys:write. The new key's type is the body's kind, inference when it names none; a scope may be granted only when the calling key holds it and a cap or ceiling no larger than its own, and a management key may be minted only by an account that owns the organization, from a key that holds no cap or ceiling of its own.

- Request field: name
- Request field: kind
- Request field: spending_cap_micros
- Request field: rate_limit_per_minute
- Request field: limit_reset
- Request field: scopes

- Response: 201 the key object, its secret, and the notice that the secret is shown once

### PATCH /v1/keys/{id}

Rename a key, disable or enable it, change its spending cap, reset window, rate limit or scopes. A present null clears that limit. Needs a key with the keys:write scope, and a scope may be granted only when the calling key holds it. A disable stops the key at once when it is written over this route, and within two seconds when it is written from the dashboard, which is the bound the key cache puts on any write that another Worker makes plus the request's own latency.

- Request field: name
- Request field: disabled
- Request field: spending_cap_micros
- Request field: rate_limit_per_minute
- Request field: limit_reset
- Request field: scopes

- Response: 200 the key object as it now stands

### DELETE /v1/keys/{id}

Delete a key of the caller's organization. The row is removed and the key stops authenticating at once. Needs a key with the keys:write scope.

- Response: 200 the id and deleted: true

### POST /v1/key/burn

End the key in the Authorization header, and only that key: the response is the key's own id and disabled: true. Every inference and management key can do this, including existing keys with no scopes. No permission grant is needed. The disable is audited, retains the row and its history, and stops the key authenticating; it cannot restore itself.

- Response: 200 the id and disabled: true

### GET /v1/activity

One page of the organization's request log, newest first: the same rows the dashboard's activity table lists and its CSV export downloads, with the same five filters. Any key of the organization may read it, and key= narrows it to one key. Query parameters: from and to (YYYY-MM-DD, UTC, both inclusive; the last 30 days by default, at most 366 days), key, model, status (ok, aborted or failed), limit (1 to 500, 100 by default) and after (the next_cursor the previous page returned).

- Response: 200 a page of activity objects and the cursor for the next page

### GET /health

Liveness and replica readiness. Needs no key.

- Response: 200 status object

### GET /health/detail

The same answer as /health plus the router's reason when it is not ready. Needs a key, because the reason names replicas.

- Response: 200 status object with the reason

### POST /v1/billing/checkout

Start a credit purchase and get the Stripe-hosted page to send the buyer to. The amount is in cents, between 1000 and 100000 (10 to 1000 dollars). Needs a key with the billing:write scope.

- Request field: amount_cents

- Response: 200 checkout session object with its url

### POST /v1/billing/purchase

Buy credit now, with no page: the charge is created and confirmed in one call, under the calling identity's purchase grant. The amount is in cents, between 1000 and 100000 (10 to 1000 dollars). The key needs no scope, because the purchase grant is the authorization, and the buyer recorded on the payment is the identity behind the key. Available in test mode; a purchase past the grant is refused with the arithmetic.

- Request field: amount_cents
- Request field: idempotency_key

- Response: 200 purchase object with the payment intent's id and status

### GET /v1/billing/credits

The organization's credit, in micro-dollars: what has been granted, what has been spent, and the balance between them. Any key of the organization may read it, so a key that spends credit can see what is left.

- Response: 200 balance object

### GET /v1/billing/payments

The organization's payments, newest first: the receipts list. No card and no customer id is returned. Needs a key with the billing:write scope, because the list carries receipt links and the reasons a payment failed.

- Response: 200 list of payment objects

### GET /v1/billing/auto-top-up

The organization's automatic top-up setting, or a null when it has none. It says whether a card is saved, never which. Needs a key with the billing:write scope.

- Response: 200 setting object, or a null

### PUT /v1/billing/auto-top-up

Write the automatic top-up setting: enabled, the threshold_micros to top up below, and the amount_micros to buy. Needs a key with the billing:write scope, and writes one audit row naming the actor and both values. Charges are capped per rolling day by the platform.

- Request field: enabled
- Request field: threshold_micros
- Request field: amount_micros

- Response: 200 the setting as it was written

### POST /v1/billing/webhook

Stripe's delivery endpoint. It needs no API key: the Stripe-Signature header is the whole authorization, and an unsigned body is refused.

- Response: 200 with what the event did to the ledger

## Chat completion parameters

Fields of POST /v1/chat/completions.

| Field | Type | What it does |
| --- | --- | --- |
| model | string | The generic deepseek-v4.1-flash name defaults to deepseek-v4.1-flash-1017-uncensored, the local uncensored checkpoint, priced and identified as such. Select hosted original weights explicitly with both hosted switches. Check each checkpoint's price before calling. |
| galatea_allow_hosted | boolean | Default false. Automatic hosted fallback is not supported. With a local DeepSeek request, true without galatea_select_hosted returns an error before inference. Naming GLM or Kimi directly requires no flag. |
| galatea_select_hosted | boolean | Default false. With galatea_allow_hosted true and model deepseek-v4.1-flash, explicitly select the hosted original weights. Without it that generic name selects the distinct local uncensored checkpoint; the response and billing identify the served checkpoint. |
| messages | array | The conversation: objects with role, content and, for tools, tool_calls or tool_call_id. A user message's content is a string, or a list of parts: text parts and, for a model whose input_modalities include image, image_url parts whose url is a base64 data: URI (png, jpeg, webp or gif, at most 4 MiB each, ten to a request). A web address is refused, not fetched. |
| stream | boolean | true streams the answer as it is generated. |
| stream_options | object | Set include_usage to get a usage block on the last chunk. |
| max_tokens | integer | The most tokens to generate. Use max_completion_tokens for the same thing in the newer spelling. |
| max_completion_tokens | integer | The same limit as max_tokens, under the newer name. |
| temperature | number | Randomness. 0 is nearly deterministic. |
| top_p | number | Nucleus sampling cut-off. |
| top_k | integer | Keep only the k most likely tokens at each step. |
| n | integer | How many answers to generate for one request. |
| stop | string or array | Stop generating when one of these strings appears. |
| seed | integer | A seed that makes repeated requests more repeatable. |
| presence_penalty | number | Penalise tokens that have appeared at all. |
| frequency_penalty | number | Penalise tokens in proportion to how often they appeared. |
| tools | array | Functions the model may call. See the Tools page. |
| tool_choice | string or object | none, auto, required, or a named function. |
| response_format | object | text, json_object or json_schema. See the JSON mode page. |
| user | string | Your own id for the end user, passed with the request. |
| reasoning_effort | string | Ask the model to think first: none, minimal, low, medium, high, or xhigh (also max). Leave it out for no reasoning, which is fastest. The thinking comes back as reasoning_content and is billed as completion tokens. |
| thinking | object | DeepSeek's switch for the same thing: {"type": "enabled"} thinks at high, {"type": "disabled"} does not. reasoning_effort wins when both are set. |

## Completion parameters

Fields of POST /v1/completions.

| Field | Type | What it does |
| --- | --- | --- |
| model | string | The generic deepseek-v4.1-flash name defaults to deepseek-v4.1-flash-1017-uncensored, the local uncensored checkpoint, priced and identified as such. Select hosted original weights explicitly with both hosted switches. Check each checkpoint's price before calling. |
| galatea_allow_hosted | boolean | Default false. Automatic hosted fallback is not supported. With a local DeepSeek request, true without galatea_select_hosted returns an error before inference. Naming GLM or Kimi directly requires no flag. The public gateway currently returns 404 for this legacy endpoint. |
| galatea_select_hosted | boolean | Default false. With galatea_allow_hosted true and model deepseek-v4.1-flash, explicitly select the hosted original weights. Without it that generic name selects the distinct local uncensored checkpoint; the response and billing identify the served checkpoint. |
| prompt | string or array | The text to continue. A turn-taking engine receives text as a user turn and prices its rendered chat prompt. Token-ID prompts cannot be sent to a turn-taking engine. |
| max_tokens | integer | The most tokens to generate. |
| temperature | number | Randomness. 0 is nearly deterministic. |
| top_p | number | Nucleus sampling cut-off. |
| top_k | integer | Keep only the k most likely tokens at each step. |
| stop | string or array | Stop generating when one of these strings appears. |
| seed | integer | A seed that makes repeated requests more repeatable. |
| presence_penalty | number | Penalise tokens that have appeared at all. |
| frequency_penalty | number | Penalise tokens in proportion to how often they appeared. |
| stream | boolean | true streams the answer. |
| stream_options | object | Set include_usage to get a usage block on the last chunk. |
| n | integer | How many answers to generate for one request. |
| echo | boolean | Return the prompt before the completion. |
| suffix | string | Text to insert after the completion. |
| best_of | integer | Generate several and return the best. |
| user | string | Your own id for the end user, passed with the request. |

## Headers

Request headers.

| Header | Value | What it does |
| --- | --- | --- |
| Authorization | Bearer <key> | Your API key. Required on every route except GET /health and the two model routes, which answer the same list to everyone. |
| Content-Type | application/json | Required on POST routes; the body is JSON. |

Response headers.

| Header | What it does |
| --- | --- |
| x-ratelimit-limit-requests | The request rate allowed for this key or organization, per minute. |
| x-ratelimit-remaining-requests | Requests left in the last minute's window. |
| x-ratelimit-reset-requests | How long until the request ceiling admits another request: 0s while it has room, and on a 429 the same number as retry-after. |
| x-ratelimit-limit-tokens | The token rate allowed in a minute. |
| x-ratelimit-remaining-tokens | Tokens left in the last minute's window. |
| x-ratelimit-reset-tokens | How long until the token ceiling admits another token, in the same shape as the request reset. |
| x-ratelimit-limit-concurrent | How many requests the organization may have in flight at once. |
| x-ratelimit-remaining-concurrent | Requests in flight that are still allowed under that cap. |
| x-ratelimit-reset-concurrent | How long until a request in flight finishes and frees a slot. |
| x-ratelimit-limit | A limit the inference plant applied, on a 402, 429 or 503 answer. |
| x-ratelimit-remaining | What is left of the plant's limit, when the plant applied one. |
| x-ratelimit-reset | When the plant's limit resets, when the plant applied one. |
| retry-after | Seconds to wait before the request can succeed. Set on the 429 and 503 answers that name a wait. |

## Responses

A chat completion answers with one JSON object. Its choices hold the answers, and usage counts the tokens. A streamed answer is a series of chunks with the same id and object set to chat.completion.chunk, each carrying a delta instead of a message.

### ChatCompletion: The answer to POST /v1/chat/completions when stream is false.

Fields of ChatCompletion.

| Field | Type | What it does |
| --- | --- | --- |
| id | string | The id of this answer. |
| object | string | Always chat.completion. |
| created | integer | Unix time, in seconds, when the answer was made. |
| model | string | The model that answered. |
| choices | array | One entry per answer: one, unless n asks for more. |
| usage | object | Token counts for the request. See the usage table. |
| system_fingerprint | string | Names the model that answered, so an answer for one model is never labelled as another's. It is derived from the model in the request, and it changes when the serving configuration behind that model changes. |

### ChatChoice: One answer inside choices.

Fields of ChatChoice.

| Field | Type | What it does |
| --- | --- | --- |
| index | integer | The position of this answer in choices, from 0. |
| message | object | The assistant message: role, content and any tool_calls. |
| finish_reason | string or null | Why generation stopped. See the Finish reason section. |
| logprobs | object or null | Token log probabilities. Null in v1. |

### ResponseMessage: The assistant message inside a choice.

Fields of ResponseMessage.

| Field | Type | What it does |
| --- | --- | --- |
| role | string | Always assistant. |
| content | string or null | The text of the answer. Null when the answer only calls tools. |
| reasoning_content | string | The model's thinking before its answer. Present only when you asked for reasoning with reasoning_effort or thinking. Streamed chunks carry it on delta.reasoning_content. |
| tool_calls | array or null | The tool calls the model asked for, when it asked for any. |
| refusal | object or null | Null in v1. |

### ModelList: The answer to GET /v1/models: every model the platform serves.

Fields of ModelList.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always list. |
| data | array | One entry per model, in catalog order. |
| engine | string or null | Internal. Absent on a production answer. |

### Model: One model, as GET /v1/models lists it and GET /v1/models/{id} answers it.

Fields of Model.

| Field | Type | What it does |
| --- | --- | --- |
| id | string | The id a request names, such as deepseek-v4.1-flash. |
| object | string | Always model. |
| created | integer | Unix time, in seconds, when the model was added. |
| owned_by | string | Who serves it: galatea. |
| name | string | The name the site shows. |
| context_length | integer | The context window in tokens, prompt and answer together. A request that does not fit is refused with context_length_exceeded. |
| max_output_tokens | integer | The most the model produces in one answer. |
| architecture | object | What the model reads and writes. |
| supported_parameters | array | The request fields the routes honour for this model. |
| pricing | object or null | The default request price in force, or null when no row is in force. |
| default_checkpoint | string or null | When present, the checkpoint used by default for this model ID. |
| hosted_original_pricing | object or null | When present, the price for explicitly selecting hosted original weights, which differ from the local default. |
| available | boolean | Whether the platform serves this model: the same list GET /health publishes. A model the platform has listed but does not serve is still reported here, with its metadata, so you can tell it from one the platform has never heard of. |

### ModelArchitecture: What a model reads and writes. Text out in v1; text in, and a picture too for a model that reads one.

Fields of ModelArchitecture.

| Field | Type | What it does |
| --- | --- | --- |
| input_modalities | array | What the model accepts: text, and image for a model that reads a picture sent in a user message. |
| output_modalities | array | What the model produces: text. |
| modality | string | The pair as one label: text->text, or text+image->text. |

### ModelPricing: The price of a model, from the price book's row in force. The unit is named by currency and per; the Models page shows the figures.

Fields of ModelPricing.

| Field | Type | What it does |
| --- | --- | --- |
| currency | string | Always USD. |
| per | string | Always million_tokens: the unit every figure is in. |
| input | string | Uncached input tokens. A string, so a published price is never rounded by a float. |
| cached_input | string or null | Input tokens read from the KV cache, or null when the row sets no cached rate. |
| output | string | Output tokens. |
| prompt_logging_discount_percent | string | Percent off the whole request when your organization opted into prompt logging. |

### Usage: The token counts of one request.

Fields of Usage.

| Field | Type | What it does |
| --- | --- | --- |
| prompt_tokens | integer | Prompt tokens processed, cached and uncached together. |
| completion_tokens | integer | Tokens generated. |
| total_tokens | integer | prompt_tokens plus completion_tokens. |
| prompt_tokens_details | object | The breakdown of prompt_tokens, including cached_tokens. |
| completion_tokens_details | object | The breakdown of completion_tokens. |
| galatea_timing | object or null | On a completed stream from our own engine, the engine's own generation interval. Absent for hosted models, aborted or truncated turns, and turns the engine did not time. |

### GalateaTiming: Engine-core elapsed generation time for one turn on our own engine, from the engine's first output token to its last. It is not GPU kernel time: engine scheduling and inter-token gaps are inside the interval.

Fields of GalateaTiming.

| Field | Type | What it does |
| --- | --- | --- |
| source | string | Always engine. A figure from any other clock is never published here. |
| decode_ms | number | Positive milliseconds between the engine's first and last output token for this request. |

### PromptTokensDetails: The breakdown of prompt_tokens. Read cached_tokens to see what the prompt cache saved.

Fields of PromptTokensDetails.

| Field | Type | What it does |
| --- | --- | --- |
| cached_tokens | integer | Of prompt_tokens, how many were prompt cache hits. |
| audio_tokens | integer | Always 0 in v1. |

### CompletionTokensDetails: The breakdown of completion_tokens. Only reasoning_tokens can be above 0 in v1.

Fields of CompletionTokensDetails.

| Field | Type | What it does |
| --- | --- | --- |
| reasoning_tokens | integer | Of completion_tokens, the ones spent thinking. 0 unless you asked for reasoning. |
| audio_tokens | integer | Audio tokens generated. |
| accepted_prediction_tokens | integer | Accepted speculative tokens. |
| rejected_prediction_tokens | integer | Rejected speculative tokens. |

### KeyObject: One API key, as /v1/keys answers it and as the dashboard's keys page reads it. Spent and remaining are folds over the usage events, taken on every read, so they can never disagree with the log.

Fields of KeyObject.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always api_key. |
| id | string | The key's stable id, key_ and 32 hex characters. Opaque. |
| name | string | What the key is for, as its owner named it. |
| prefix | string | The visible stub of the secret: the eight characters after its gal- marker. Never enough of the secret to be one. |
| created_at | integer | When it was minted, epoch milliseconds. |
| created_by | string | The account that minted it. |
| last_used_at | integer or null | When it last authenticated a request, epoch milliseconds, or null when it never has. |
| disabled | boolean | True when the key no longer authenticates. |
| kind | string | The key's type: inference, which calls the models, or management, which manages the organization's keys, usage and billing. Fixed at mint, and each kind is refused on the other's routes. |
| scopes | array | The scopes it holds: billing:write, keys:burn, keys:write, or none. An inference key holds keys:burn or none; a management key may hold any of the three. |
| spending_cap_micros | integer or null | The key's own cap in micro-dollars, or null when it spends the organization's credit with no cap of its own. |
| spent_micros | integer | Micro-dollars spent in the key's own reset window, folded from the usage events on this read. |
| remaining_micros | integer or null | The cap less the spend, or null when the key has no cap. |
| rate_limit_per_minute | integer or null | The key's own request ceiling, or null for the organization's. |
| limit_reset | string | The window the cap resets on: never, daily, weekly or monthly. |

### ActivityObject: One request, as /v1/activity answers it and as the dashboard's activity table and CSV export read it. The cost is the ledger's pricing rule applied to the usage event and the price row it names, taken on this read.

Fields of ActivityObject.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always activity. |
| request_id | string | The request's id, which is also the id the ledger charges against. |
| received_at | integer | When the edge accepted the request, epoch milliseconds. |
| key_id | string | The key that authenticated it. |
| key_name | string | That key's name, or its id when the key has been deleted. |
| model | string | The model that served it. |
| status | integer | The request status number: 1 ok, 2 aborted, 3 failed before the first token, 4 failed mid-stream. |
| status_label | string | That number in words: ok, aborted, failed or unknown. |
| input_tokens | integer | Prompt tokens processed, cached and uncached together. |
| cached_input_tokens | integer | Of input_tokens, the KV cache hits. |
| output_tokens | integer | Tokens generated. |
| prompt_logging | boolean | True when the organization had opted into prompt logging for this request and took the discount. |
| cost_micros | integer | Micro-dollars it cost, by the ledger's rule. Zero when price_missing is true. |
| cost_usd | string | The same amount as a six-decimal dollar string, such as 1.234567. |
| price_missing | boolean | True when the price row the request was charged at is not stored. The request is reported rather than priced at zero. |
| price_book_row_id | string | The price book row it was charged at. |
| ttft_ms | integer | Milliseconds from the edge accepting the request to its first output token. The edge's own clock: the latency every Galatea surface publishes for this request. |
| total_ms | integer | Milliseconds from the edge accepting the request to its last output token. The edge's own clock and the request's headline latency: a client's stopwatch reads this, less one network round trip. |
| replica_ttft_ms | integer | The replica's own report: milliseconds to its first output token. A breakdown under ttft_ms, never the headline, because the replica's clock starts later. Zero when the replica reported nothing. |
| replica_total_ms | integer | The replica's own report: milliseconds to its last token. |
| replica_decode_ms | integer | The replica's own decode time, in milliseconds: the generation itself, and the span the rate is measured over when the replica reported one. |
| queue_ms | integer | Milliseconds the replica waited before prefill began, as the replica reported it. |
| prefill_ms | integer | Milliseconds the replica spent prefilling the uncached prompt, as the replica reported it. |
| tokens_per_second | number or null | Output tokens per second over the decode span, one decimal: the serving engine's own decode time where it reported one, and the edge's span between its first and last output token where it did not. Null when the answer is too short to measure: fewer than 16 output tokens, or under 100 ms of decoding, or no output at all. Short answers are not rates. |

### ModelList: The answer to GET /v1/models.

Fields of ModelList.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always list. |
| data | array | One entry per model this key may call. |
| engine | string or null | Which engine answered the list, when the edge reports one. Absent rather than guessed when it does not. |

### Model: One model in the catalog, as GET /v1/models and GET /v1/models/{id} answer it. A model that is not live is still listed with its metadata: it exists and it is priced.

Fields of Model.

| Field | Type | What it does |
| --- | --- | --- |
| id | string | The model id, the string a request names, such as deepseek-v4.1-flash. |
| object | string | Always model. |
| created | integer | Unix seconds when the model was added. |
| owned_by | string | Who serves it. |
| name | string | The name a reader sees on the site. |
| context_length | integer | Context window in tokens: prompt and output together. |
| max_output_tokens | integer | The largest output the model will produce in one answer. |
| architecture | object | What the model reads and writes. |
| supported_parameters | array | The request parameters the routes honour for this model. |
| pricing | object or null | The default request price, or null when no row is in force. |
| default_checkpoint | string or null | When present, the checkpoint used by default for this model ID. |
| hosted_original_pricing | object or null | When present, the price for explicitly selecting hosted original weights, which differ from the local default. |
| available | boolean | Whether the model answers requests now. |

### Architecture: What a model reads and writes, inside the model object.

Fields of Architecture.

| Field | Type | What it does |
| --- | --- | --- |
| input_modalities | array | The kinds of input the model accepts. |
| output_modalities | array | The kinds of output the model produces. |
| modality | string | The pair as one label, such as text->text or text+image->text. |

### Pricing: The price of a model, inside the model object. Every figure is a string: the book stores integer micro-dollars and a float here would round a published figure. cached_input is null when the book's row leaves it unset, which is a different statement from a cached token costing nothing.

Fields of Pricing.

| Field | Type | What it does |
| --- | --- | --- |
| currency | string | Always USD. |
| per | string | Always million_tokens: the unit every figure is quoted in. |
| input | string | Uncached input. |
| cached_input | string or null | Input read from the KV cache, or null when the row has no cached rate. |
| output | string | Output. |
| prompt_logging_discount_percent | string | The discount the whole request gets when the organization opted into prompt logging, as a string. |

### KeyInfo: The answer to GET /v1/key: the calling key's own record, in OpenRouter's shape, so a tool that reads one reads the other.

Fields of KeyInfo.

| Field | Type | What it does |
| --- | --- | --- |
| data | object | The record. |

### KeyInfoData: The record GET /v1/key returns. Every figure is the calling key's, and every number is a fold over the ledger events, taken on read. The organization's own position is beside it under organization.

Fields of KeyInfoData.

| Field | Type | What it does |
| --- | --- | --- |
| label | string | A label that identifies the key without revealing it. |
| org_id | string | The organization the key belongs to. |
| key_id | string | The key's stable id. |
| limit | number or null | This key's own spending cap in dollars, from its row, or null when the key has no cap and spends the organization's credit. |
| usage | number | What this key has been charged over its whole life, in dollars. |
| usage_daily | number | What this key has been charged since the start of the current UTC day, in dollars. |
| usage_weekly | number | What this key has been charged since the start of the current ISO week, in dollars. |
| usage_monthly | number | What this key has been charged since the start of the current UTC month, in dollars. |
| limit_remaining | number or null | limit less what this key has spent in the window its cap resets on, in dollars, or null when it has no cap. This is the headroom the request path decides against. |
| limit_reset | string | The window the cap resets on: never, daily, weekly or monthly. |
| limit_resets_at | integer or null | When that window next turns, unix seconds, or null for a cap that never resets. |
| is_free_tier | boolean | True for an account that cannot be charged. |
| rate_limit | object | This key's request ceiling. |
| prompt_logging | object | Whether the organization opted into prompt logging, and the discount with it. |
| organization | object | The organization behind the key: its balance is the org's, named as the org's. |

### OrgPosition: The organization behind a key, inside GET /v1/key. Its own cap and balance, which fund every key the organization holds.

Fields of OrgPosition.

| Field | Type | What it does |
| --- | --- | --- |
| id | string | The organization's id. |
| limit | number or null | The organization's credit limit in dollars, or null when uncapped. |
| usage | number | What the organization has spent, in dollars. |
| balance | number | What the organization has left, in dollars: grants plus adjustments less spend. |

### RateLimit: The rate limit block of GET /v1/key.

Fields of RateLimit.

| Field | Type | What it does |
| --- | --- | --- |
| requests | integer or null | Requests allowed per interval: the key's own ceiling when its row sets one, the organization's when it does not. |
| interval | string | The interval. The limiter's windows are sixty seconds, so this is 1m. |

### PromptLogging: The prompt logging block of GET /v1/key.

Fields of PromptLogging.

| Field | Type | What it does |
| --- | --- | --- |
| enabled | boolean | True when the organization opted in. |
| discount | number | The discount, as a fraction, applied to the price when enabled. |

### KeyList: The answer to GET /v1/keys: every key of the organization, newest first.

Fields of KeyList.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always list. |
| data | array | The keys, each with the spend in its own reset window and what is left under its cap. |

### KeyCreated: The answer to POST /v1/keys, and the only answer that carries a secret.

Fields of KeyCreated.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always api_key. |
| key | object | The key as it now stands. |
| secret | string | The key itself, shown here and nowhere else. Only its hash and visible prefix are stored. |
| secret_notice | string | The sentence that says the secret is shown once, so a caller can show it without writing its own copy. |

### KeyUpdated: The answer to PATCH /v1/keys/{id}: the key as it now stands.

Fields of KeyUpdated.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always api_key. |
| key | object | The key after the change. |

### KeyBurned: The answer to POST /v1/key/burn. The calling key has just disabled itself, so the answer names it and nothing else.

Fields of KeyBurned.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always api_key. |
| id | string | The id of the key that was burnt: the one the request authenticated with. |
| disabled | boolean | Always true. A second burn is a 401, because a burnt key no longer authenticates. |

### KeyDeleted: The answer to DELETE /v1/keys/{id}. The row is gone, so there is no key object to return.

Fields of KeyDeleted.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always api_key. |
| id | string | The id that was deleted. |
| deleted | boolean | Always true: a key that was not there is a 404 rather than this answer. |

### ActivityPage: One page of GET /v1/activity. A cursor is a position, not an offset: pass next_cursor back as after.

Fields of ActivityPage.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always list. |
| data | array | The requests on this page, newest first. |
| next_cursor | string or null | Where the next page starts, or null when this page was the last one. |

### Credits: The answer to GET /v1/billing/credits: the organization's balance, folded from the ledger events on this read.

Fields of Credits.

| Field | Type | What it does |
| --- | --- | --- |
| mode | string | The mode of the Stripe key the Worker holds: test, or unknown for a key that is neither. |
| org_id | string | The organization. |
| balance_micros | integer | What is left to spend, in micro-dollars. |
| granted_micros | integer | Everything added: grants, purchases, adjustments up. |
| spent_micros | integer | Everything spent: charges and adjustments down. |
| currency | string | Lower-cased, so a balance and a receipt name one currency. |
| computed_at | integer or null | Unix seconds when the balance was folded, when the ledger reports one. |

### PaymentList: The answer to GET /v1/billing/payments: the receipts list, newest first.

Fields of PaymentList.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always list. |
| data | array | The payments on this page. |
| next_cursor | string or null | Where the next page starts, or null when this page was the last one. |

### Payment: One Stripe payment the platform saw. No card, customer id or payment method id is ever returned.

Fields of Payment.

| Field | Type | What it does |
| --- | --- | --- |
| id | string | The row id, derived from the Stripe object it describes. |
| org_id | string | The organization the money belongs to. |
| kind | string | top_up for a purchase a buyer started, auto_top_up for one the platform made. |
| status | string | pending until the webhook settles it, then succeeded or failed. |
| amount_micros | integer | The amount, in micro-dollars. |
| currency | string | Lower-cased. |
| receipt_url | string or null | Stripe's hosted receipt, when it has one. |
| payment_intent_id | string or null | The payment intent, when the payment has one. |
| checkout_session_id | string or null | The checkout session, when the payment came from one. |
| failure_reason | string | Why a payment failed. Empty otherwise. |
| created_at | integer | Unix seconds when this platform first saw the payment. |

### CheckoutSession: The answer to POST /v1/billing/checkout: the Stripe-hosted page to send the buyer to.

Fields of CheckoutSession.

| Field | Type | What it does |
| --- | --- | --- |
| id | string | The session id. |
| url | string or null | The hosted page. Null when Stripe did not mint one. |
| amount_cents | integer | The total, in cents. |
| currency | string | Lower-cased. |
| org_id | string | The organization the credit lands in. |

### Purchase: The answer to POST /v1/billing/purchase: the charge, created and confirmed in one call.

Fields of Purchase.

| Field | Type | What it does |
| --- | --- | --- |
| object | string | Always purchase. |
| payment_intent_id | string | The payment intent Stripe created. |
| status | string | The payment intent's status as Stripe reports it, such as succeeded. |
| amount_cents | integer | The amount, in cents. |
| amount_micros | integer | The same amount, in micro-dollars. |
| currency | string | Lower-cased. |
| org_id | string | The organization the credit lands in. |
| buyer | string | The identity the charge is attributed to, which is the buyer the payment row will carry. |
| mode | string | The mode the Stripe key is in. This route exists only in test mode. |

### AutoTopUp: The answer to GET and PUT /v1/billing/auto-top-up.

Fields of AutoTopUp.

| Field | Type | What it does |
| --- | --- | --- |
| auto_top_up | object or null | The setting, or null when the organization has none. |

### AutoTopUpSettings: The automatic top-up setting, as the route answers it. The card is never echoed: has_payment_method says a card is saved, never which.

Fields of AutoTopUpSettings.

| Field | Type | What it does |
| --- | --- | --- |
| org_id | string | The organization. |
| enabled | boolean | Whether the feature is on. A failed charge sets it to false. |
| threshold_micros | integer | Charge when the balance falls below this, in micro-dollars. |
| amount_micros | integer | Charge this much, in micro-dollars. |
| has_payment_method | boolean | True when a card is saved for the organization. |
| disabled_at | integer or null | Unix seconds when a failure switched it off. |
| disabled_reason | string or null | Why it is off. |

## Finish reason

Every choice carries a finish_reason that says why the answer ended. Branch on it: tool_calls means run the tools, length means the answer was cut off.

Values of finish_reason.

| Value | Meaning |
| --- | --- |
| stop | The model finished its answer, or reached one of your stop sequences. |
| length | The answer hit max_tokens or max_completion_tokens and was cut off. A tool call cut off this way is also length. |
| tool_calls | The model stopped to call one or more tools. Run them, then send the results back as tool messages. |
| aborted | The request was cancelled by the caller before it finished. The answer may be partial. |
| error | The model server failed part way through. The answer may be partial; retry the request. |
| null | Still generating. Streamed chunks carry null until the chunk that ends the answer. |

## Errors

The error codes are shared by all routes. Each code is listed once below, with its status, and a route answers with the codes its request can trigger.

Every error code the API answers with.

| Status | Code | Type | When | Retry | Fix |
| --- | --- | --- | --- | --- | --- |
| 400 | none | invalid_request_error | The body is not valid JSON, or a field has the wrong type or value. The param field names the field. | no | - |
| 400 | context_length_exceeded | invalid_request_error | The prompt plus max_tokens is longer than the model's context window. Shorten the prompt or lower max_tokens. | no | - |
| 400 | invalid_signature | invalid_request_error | A Stripe webhook arrived without a Stripe-Signature header, with one that does not match the endpoint secret, or with a timestamp outside the five minutes the platform accepts. Only Stripe sees this. | no | - |
| 400 | max_tokens_too_large | invalid_request_error | The prompt plus the output ceiling is charged more tokens than the organization may spend in a minute, so the request can never be admitted. Lower max_tokens or shorten the prompt. | no | - |
| 401 | invalid_api_key | authentication_error | The Authorization header names a key the platform does not know. Copy the key again from the Keys page; a key is shown once, when it is made. | no | https://galatea.co/api/dashboard/keys |
| 401 | key_disabled | authentication_error | This key was disabled. Enable it on the Keys page, or make another key. | no | https://galatea.co/api/dashboard/keys |
| 401 | key_expired | authentication_error | This key passed its expiry. Make another key on the Keys page. | no | https://galatea.co/api/dashboard/keys |
| 401 | malformed_authorization | authentication_error | The Authorization header is not of the form Bearer <key>. | no | https://galatea.co/api/dashboard/keys |
| 401 | missing_authorization | authentication_error | No Authorization header was sent, or it carried no token. Send the key as Authorization: Bearer <key>. | no | https://galatea.co/api/dashboard/keys |
| 402 | insufficient_credit | insufficient_quota | The organization's own balance is spent, for every key it has. Add credit on the Credits page. This is not a key cap: a key cap answers key_limit_exceeded. | no | https://galatea.co/api/dashboard/credits |
| 402 | key_limit_exceeded | insufficient_quota | This key's own spending cap is spent for the window named by limit_window. Raise the cap on the Keys page, make another key, or wait until resets_at. limit_source is key_cap, and the organization's balance is untouched. | no | https://galatea.co/api/dashboard/keys |
| 403 | budget_exceeded | insufficient_quota | The organization has reached the spend budget set for the window named by limit_window: the most it may spend across every key it holds. Nothing was charged. limit is the budget in micro-dollars and remaining is the headroom left (zero), so limit minus remaining is the spend at the moment of refusal; resets_at is when the window turns, absent for a lifetime budget. limit_source is org_budget. Raise or remove the budget on the Credits page, or wait for resets_at. | no | https://galatea.co/api/dashboard/credits |
| 403 | abuse_hold | permission_error | An operator has held this key, the account that minted it or its organization. The message quotes the reason the operator wrote. Contact support at george@galatea.co. | no | - |
| 403 | account_disabled | permission_error | The account that minted this key is disabled. Its keys stop authenticating, it cannot mint another, and the sessions it was signed into are ended. Contact support at george@galatea.co. | no | - |
| 403 | account_on_hold | permission_error | An operator has put this organization or this key on hold, as the request path reads it before a request is admitted. The message says why. Contact support to have it lifted. | no | - |
| 403 | org_suspended | permission_error | The organization is suspended, so none of its keys can spend. Contact support at george@galatea.co. | no | - |
| 403 | permission_denied | permission_error | The key is valid but may not do this, for example a key without the scope the route needs. | no | - |
| 404 | model_not_found | invalid_request_error | The model does not exist or this key cannot use it. The param field is model. | no | - |
| 403 | provider_excluded | permission_error | Your organization's routing policy excludes every provider that serves this model, so the router had no replica it was allowed to use. The message names the companies you excluded. Nothing was charged. Change the policy on the Settings page, under Provider routing; waiting does not change the answer. | no | https://galatea.co/api/dashboard/settings |
| 404 | key_not_found | invalid_request_error | No key with that id is in the caller's organization. A key of another organization answers this rather than a 403, so the route cannot be used to probe what other accounts hold. | no | https://galatea.co/api/dashboard/keys |
| 404 | unknown_url | invalid_request_error | No route answers this path. Check the path and the version prefix /v1. | no | - |
| 405 | method_not_allowed | invalid_request_error | The path exists but not for this method. The Allow header lists the methods it does answer. | no | - |
| 413 | request_too_large | invalid_request_error | The request body is larger than the API reads. The message names the limit. Send a smaller request: a prompt that fits the model's context window always fits. | no | - |
| 429 | concurrency_limit_exceeded | rate_limit_error | The organization already has as many requests in flight as it is allowed. Retry-After says when to try again; slow down or ask for a higher cap. | after the wait in Retry-After | - |
| 429 | rate_limit_exceeded | rate_limit_error | A request or token rate ceiling was reached, for this key or for the organization. The message names which one (requests per minute, or tokens per minute). Retry-After says when to try again, and it is the same number as the reset of the ceiling that refused. | after the wait in Retry-After | - |
| 500 | internal_error | server_error | The model server failed, or a stream broke before it finished. Retry the request; the message says what happened. | yes | - |
| 501 | unimplemented | server_error | The request asks for something v1 does not do yet, such as a model feature that is not served. | no | - |
| 502 | payment_provider_error | server_error | Stripe could not be reached, or answered with a server error, while a purchase or a top-up was being started. Retry shortly. | yes | - |
| 503 | no_capacity | server_error | No healthy replica can take the request right now. Retry after a short wait. | after the wait in Retry-After | - |
| 503 | server_error | server_error | The inference plant is not accepting the gateway's own credentials. This is ours to fix; retry shortly. | yes | - |
| 503 | service_unavailable | server_error | The gateway could not reach its own storage or rate limiter for this request: one connection was lost and the retry did not get through. Nothing was charged and the request reached no model. Retry after the wait in Retry-After; an SDK retries 503 on its own. | after the wait in Retry-After | - |
| 504 | deadline_exceeded | server_error | The request ran longer than the platform allows. Lower max_tokens or retry. | yes | - |

### Fields a program branches on

The envelope is OpenAI's, and it carries three fields beyond it so a program can act on a refusal instead of reading it. limit_source says which limit stopped the request. resets_at is the unix second that limit lifts, when a wait reaches it. remedy_url is the page that fixes it. limit_window names the cap's window when the refusal is a key cap.

The two money refusals, told apart.

| Code | Status | limit_source | resets_at | remedy_url |
| --- | --- | --- | --- | --- |
| insufficient_credit | 402 | org_credit | absent: a top-up lifts it, not a clock | https://galatea.co/api/dashboard/credits |
| key_limit_exceeded | 402 | key_cap | the second the cap's window turns | https://galatea.co/api/dashboard/keys |

Never branch on the status alone for these two: both are 402 and the same type. Branch on the code, or on limit_source.

```a key whose own cap is spent
{
  "error": {
    "message": "This key has reached its spending cap. Raise the cap at https://galatea.co/api/dashboard/keys, make another key, or wait for the cap's window to turn.",
    "type": "insufficient_quota",
    "param": null,
    "code": "key_limit_exceeded",
    "remedy_url": "https://galatea.co/api/dashboard/keys",
    "resets_at": 1792368000,
    "limit_window": "daily",
    "limit_source": "key_cap"
  }
}
```
