Skip to API documentation
API REFERENCE

OpenAI-compatible.
Explicit by design.

Newton’s implements a focused, text-only Chat Completions surface with pinned model IDs, prepaid balances, streaming, and USD request receipts. It does not claim compatibility with every OpenAI or Anthropic endpoint.

01 / FIRST COMPLETION

List, select, run.

Install the OpenAI Python SDK, keep your key in the environment, then select an exact ID from the live catalog. Do not hard-code a model name that the catalog did not return.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://newtons.dev/api/v1",
    api_key=os.environ["NEWTONS_API_KEY"],
)

catalog = client.models.list()
if not catalog.data:
    raise RuntimeError("No models published.")

model_id = catalog.data[0].id
completion = client.chat.completions.create(
    model=model_id,
    messages=[{"role": "user", "content": "Reply exactly: Newton's connected"}],
    max_tokens=32,
)

print(completion.choices[0].message.content)
print("resolved model:", completion.model)

Expected application result: a normal Chat Completion whose model matches the selected published ID. The JSON response also contains a newtons receipt object. Keep the key out of source code, chat, logs, screenshots, and committed files.

{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "model": "<published-model-id>",
  "choices": [{ "index": 0, "message": { "role": "assistant", "content": "Newton's connected" } }],
  "usage": { "prompt_tokens": 12, "completion_tokens": 4, "total_tokens": 16 },
  "newtons": {
    "request_id": "…",
    "requested_model": "<published-model-id>",
    "resolved_model": "<published-model-id>",
    "fallback_used": false,
    "cost_usd": "…",
    "balance_usd": "…",
    "cost_estimated": false
  }
}
02 / AGENT ONBOARDING

Give your coding agent the job.

Paste this into Codex, Claude Code, Cursor, Copilot, or another repo-aware agent. The prompt fails closed when the key or published catalog is unavailable.

NEWTONS_AGENT_PROMPT.md
Onboard this repository to Newton’s model API.

Security rules:
- Never ask me to paste, echo, or reveal the API key in chat, source code, command arguments, logs, or committed files.
- Read the key only from the NEWTONS_API_KEY process environment variable.
- If NEWTONS_API_KEY is missing, stop and tell me how to set it in my local shell or secret manager without asking for its value.
- Ensure .env and .env.local are ignored by git. Keep .env.example safe to commit and free of real secrets.

Implementation:
1. Use the project’s existing OpenAI SDK. Set base_url to https://newtons.dev/api/v1 and api_key to NEWTONS_API_KEY from the environment.
2. Call client.models.list() and choose only an exact model ID returned by the published catalog. If the list is empty, stop and report: “No models published.”
3. Make one non-streaming chat completion smoke test with max_tokens=16 and the user message: “Reply exactly: Newton’s connected”.
4. Confirm the requested model matches the resolved model. Report the request ID and USD cost headers when the SDK exposes them.
5. Keep the change minimal. Report the files changed, selected model ID, and smoke-test result.

Do not invent a model ID, enable an undisclosed fallback, print the key, or commit a secret.

SECRETENV ONLYCATALOGLIVE /MODELSTEST1 CALL
03 / ROUTES

Focused surface.

Use https://newtons.dev/api/v1 as the SDK base URL. All routes require Authorization: Bearer $NEWTONS_API_KEY.

GET/models

List exact model IDs currently published to your account.

GET/pricing

Read USD input, cached-input, output, reasoning, tool, and fixed-request rates.

GET/balance

Read available, reserved, promotional, and purchased service-credit balances.

POST/chat/completions

Create non-streaming or streaming, text-only Chat Completions.

04 / STREAMING

Read through the final receipt.

Set stream=True and consume the stream until [DONE]. Newton’s appends a terminal chunk with empty choices and the settled newtons receipt before the done sentinel.

stream = client.chat.completions.create(
    model=model_id,
    messages=[{"role": "user", "content": "Explain inertia in one sentence."}],
    max_tokens=80,
    stream=True,
)

receipt = None
for chunk in stream:
    if chunk.choices:
        text = chunk.choices[0].delta.content
        if text:
            print(text, end="", flush=True)
    extra = getattr(chunk, "model_extra", None) or {}
    receipt = extra.get("newtons") or receipt

print("\\nreceipt:", receipt)

The HTTP receipt headers at stream start are an authorization estimate. The terminal receipt is the settled result. If the stream emits an error event, treat it as terminal and do not execute tool side effects from an incomplete response.

05 / ERRORS + RETRIES

Retry by class, not by instinct.

HTTP errors and recommended client behavior
StatusTypical typeWhat to do
400invalid_request_errorFix the JSON, message shape, text-only content, or output-token value. Do not retry unchanged.
401authentication_errorCheck that the environment contains an active newt_… key. Never log the key.
402insufficient_balanceReduce max_tokens or add service credit. Do not automatically retry.
403account_lockedStop traffic and contact support. Do not rotate through accounts or keys.
404model_not_foundRefresh GET /models and select a currently published ID.
413invalid_request_errorReduce the serialized request below 128 KB.
429rate_limit_errorHonor Retry-After, then retry with jitter. Reduce parallelism if concurrency is the cause.
502route_unavailable or identity errorRetry a transient route error with bounded backoff. Do not loop on a model-identity error; refresh the catalog or contact support.
503route, capacity, price, or wallet unavailableCheck status and the live catalog. Retry a small number of times with exponential backoff; stop if the condition persists.
Recommended retry envelope

At most four total attempts for 429, transient 502, or 503: honor Retry-After when present, otherwise wait approximately 1s, 2s, then 4s with random jitter. Cap the delay and total deadline in your own application.

A retry can create a second billable completion if the first request finished upstream but its response was lost. Retry only operations your application can safely repeat, and never retry a completed tool side effect merely because its reporting request failed.

06 / LIMITS

Known envelopes.

20 RPM

Promotional access

1

Promotional concurrency

60 RPM

Funded access

4

Funded concurrency

8,192

Maximum output tokens

128 KB

Maximum request body

Capacity, safety, fraud, balance, and model-availability controls also apply. A rate or concurrency response uses 429 and includes Retry-After.

07 / RECEIPTS

Every accepted call accounts for itself.

x-newtons-request-cost-usd
x-newtons-balance-usd
x-newtons-cost-estimated
x-newtons-request-id
x-newtons-requested-model
x-newtons-resolved-model
x-newtons-fallback-used
x-newtons-rpm-limit
x-newtons-concurrency-limit

Usage is reserved before inference, reconciled against returned usage, and settled in integer micro-USD internally. Receipts are accounting metadata, not cryptographic attestations. Save the request ID—not the prompt or API key—when asking for support.

08 / ROUTING

Pinned means no silent swap.

A published model ID remains pinned to that route. Newton’s requires the upstream-reported ID to match; mismatched or unconfirmed responses fail closed. If you explicitly provide documented fallback_models, Newton’s may try up to three of those published IDs in the order supplied and reports whether a fallback was used.

Automatic model routing is not currently part of the public API.

09 / SUPPORT MATRIX

Know what is—and is not—implemented.

Public API compatibility at launch
CapabilitySupportNotes
OpenAI Chat CompletionsSupportedText-only, n=1, non-streaming and streaming.
Model, pricing, and balance listsSupportedAuthenticated Newton’s routes under /api/v1.
Tool-call payloadsRoute-dependentPassed through on published models that accept the supplied tool schema.
Explicit fallback modelsSupportedNewton’s extension; up to three published IDs. Never implicit.
Images, audio, video, and filesNot supportedThe launch Chat Completions surface accepts text content only.
OpenAI Responses, Assistants, embeddings, batches, fine-tuningNot supportedUse only the documented routes above.
Anthropic Messages APINot supportedNewton’s does not currently expose a native /messages adapter.
Automatic model routingNot supportedSelect a catalog ID or provide explicit fallback IDs.

Service incident? Check newtons.dev/status before retrying.

Account, billing, or model mismatch? Email founders@newtons.dev with the request ID, UTC timestamp, endpoint, and error type. Never send your API key or full prompt.

Security issue? Follow security.txt and include a minimal reproduction without customer data.