MoonCo API integration
MoonCo exposes an OpenAI-compatible API at:
https://api.moonco.one/v1
All requests use HTTPS and bearer authentication. Set the API key and the model ID issued to your account in your process environment:
export MOONCO_API_KEY="your-api-key"
export MOONCO_MODEL_ID="your-issued-model-id"
Send it on every request as Authorization: Bearer $MOONCO_API_KEY. The examples below also
accept MOONCO_API_BASE_URL so they can be checked against a local test route; applications can
leave that variable unset.
Chat completions
POST /v1/chat/completions supports this small OpenAI-compatible request subset:
model: use a model ID returned byGET /v1/models;messages: one or more ordered objects withrole(system,user, orassistant) and stringcontent;stream:falsefor one JSON response ortruefor server-sent event chunks;max_completion_tokens: positive output-token ceiling up to 32,768;temperature: number from0through2;top_p: number greater than0through1;stop: one string or an array of strings;
For SDK compatibility, MoonCo also accepts stream_options with include_usage, deprecated
max_tokens in place of max_completion_tokens, and n set to 1; usage remains included and
only one choice is returned. Other request fields are not part of the public contract and can be
rejected.
MoonCo forwards accepted sampling controls to a model endpoint that supports them. These controls can influence generation, but they do not guarantee reproducible output.
Non-streaming curl
curl --fail-with-body --silent --show-error \
"${MOONCO_API_BASE_URL:-https://api.moonco.one/v1}/chat/completions" \
--header "Authorization: Bearer ${MOONCO_API_KEY}" \
--header "Content-Type: application/json" \
--data "{\"model\":\"${MOONCO_MODEL_ID:?Set MOONCO_MODEL_ID to an ID returned by /v1/models}\",\"messages\":[{\"role\":\"user\",\"content\":\"Reply with a short greeting.\"}],\"stream\":false}"
Streaming curl
curl --fail-with-body --silent --show-error --no-buffer \
"${MOONCO_API_BASE_URL:-https://api.moonco.one/v1}/chat/completions" \
--header "Authorization: Bearer ${MOONCO_API_KEY}" \
--header "Content-Type: application/json" \
--data "{\"model\":\"${MOONCO_MODEL_ID:?Set MOONCO_MODEL_ID to an ID returned by /v1/models}\",\"messages\":[{\"role\":\"user\",\"content\":\"Reply with a short greeting.\"}],\"stream\":true}"
Streaming responses use server-sent events. Each event begins with data: and contains a JSON
chat-completion chunk. The stream ends with data: [DONE]. Read incremental text from
choices[].delta.content; inspect the final choice finish reason and final usage when present.
OpenAI Python SDK
Install and import the current openai package, then provide MoonCo's API base URL:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MOONCO_API_KEY"],
base_url=os.environ.get("MOONCO_API_BASE_URL", "https://api.moonco.one/v1"),
)
response = client.chat.completions.create(
model=os.environ["MOONCO_MODEL_ID"],
messages=[{"role": "user", "content": "Reply with a short greeting."}],
)
print(response.choices[0].message.content)
Models
GET /v1/models returns the public model IDs available to the calling key.
curl --fail-with-body --silent --show-error \
"${MOONCO_API_BASE_URL:-https://api.moonco.one/v1}/models" \
--header "Authorization: Bearer ${MOONCO_API_KEY}"
Use a returned data[].id value as model in chat-completion requests. Applications should not
depend on the ordering of the returned list.
Account
GET /v1/account uses the same API key and returns its authenticated account summary.
curl --fail-with-body --silent --show-error \
"${MOONCO_API_BASE_URL:-https://api.moonco.one/v1}/account" \
--header "Authorization: Bearer ${MOONCO_API_KEY}"
The response includes the account display name, credit totals, estimated remaining credit,
exhaustion state, an as_of timestamp, allowed public model IDs, and the calling key's alias and
masked identifier. limits.rpm and limits.tpm report the authenticated team's current shared
request and token ceilings across all of its keys. retention_policy reports
the policy applied prospectively when each new request is admitted: zero-content, 30-days,
90-days, 365-days, or indefinite. Treat as_of as the freshness boundary. These fields are
authenticated account data; this documentation does not publish any team's configured values.
Response fields
A non-streaming chat response follows the OpenAI-compatible shape:
id: MoonCo request identifier;object,created, andmodel: response metadata;choices[].index: choice position;choices[].message.roleandchoices[].message.content: generated message;choices[].finish_reason: why generation stopped;usage.prompt_tokens,usage.completion_tokens, andusage.total_tokens: token counts;usage.billable_cost_microusd: the request's MoonCo billable cost as a whole number of millionths of one US dollar.
The final streaming event uses the same usage shape. Cost is an integer to avoid floating-point
money ambiguity. Clients should ignore additional response fields they do not recognize.
Errors and retries
Errors use an HTTP status and a JSON error body. Do not depend on error prose; branch on the status and keep request identifiers when available for support.
400: correct the request before trying again.401or403: check the key and its access, then stop automatic retries.404: check the path and public model ID.429: wait before trying again and honorRetry-Afterwhen supplied.5xx, connection failure, or timeout: retry with capped exponential backoff and jitter.
Use a small retry limit. A retried chat POST can start a new completion, so retry only when your
application can tolerate another generation. Do not attempt to resume a disconnected stream;
start a new request if that behavior is acceptable.
API-key safety
- Keep keys in a secret manager or protected process environment, not source code.
- Never place a key in a URL, query string, browser bundle, log, screenshot, or support message.
- Send keys only to the MoonCo HTTPS API base URL.
- Use separate keys for separate applications when issued, and revoke a key that may be exposed.
- Do not embed a key in software distributed to end users.
For integration support, email support@moonco.io. Do not include API keys, request content, or other secrets.