hi ▾

Moonshot API Quickstart Guide

Connect your application to the moonshot API using standard OpenAI-compatible endpoints. This guide covers authentication, payload structure, and streaming for unrestricted content generation.

Authentication & Base URL Setup

The moonshot API requires a valid API key for every request. Pass your key in the Authorization header as a Bearer token. Your base URL is https://api.apimoonshot.cc/v1. This endpoint works with any standard OpenAI-compatible client by simply updating the base URL and injecting your key.

Chat Completions Endpoint (POST /v1/chat/completions)

Send your prompts to the chat completions endpoint to receive text responses. Use the model ID uncensored to ensure no content refusals for lawful adult use. The endpoint accepts standard message arrays and returns generated text directly.

curl https://api.apimoonshot.cc/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [{"role": "user", "content": "List 3 key differences between Rust and Go concurrency models"}]
  }'

Model Listing & Configuration (GET /v1/models)

Verify available models and endpoint configuration by querying the models list. This confirms your authentication is correct and the service is responsive. The response will list the uncensored model ID for your integration.

from openai import OpenAI

client = OpenAI(base_url="https://api.apimoonshot.cc/v1", api_key="YOUR_KEY")

resp = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)

Streaming Responses with SSE

Enable server-sent events (SSE) by setting stream: true. This returns tokens incrementally, allowing your application to display output in real time. Token usage statistics appear in the final chunk of the stream.

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.apimoonshot.cc/v1", apiKey: process.env.API_KEY });

const resp = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);

Parameters: Temperature, Top P, and JSON Mode

Control generation behavior using temperature, top_p, and stop sequences. Enable strict JSON output with response_format: {"type": "json_object"}. Function calling and tool definitions are also supported for complex workflows.

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Tell the story in second person."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Error Handling and Rate Limits

Monitor HTTP status codes for standard errors: 401 for invalid keys, 402 for insufficient credit, and 429 for rate limits. The API allows 300 requests per minute and 8 concurrent requests per key. Requests fail fast if the 8 MB body limit is exceeded.

FAQ

What is the context window size for the uncensored model?

The model supports a 100,000 token context window for both prompt and completion combined. The maximum output per request is 16,000 tokens, or 2,048 tokens if <code>max_tokens</code> is not explicitly set.

How do I handle errors when my credit runs out?

The API returns a 402 status code when prepaid credit is exhausted. Errors and refusals do not consume tokens, so you only pay for successful completions. Top up via USDT or USDC to resume service immediately.

Is the moonshot API key secure for production use?

Yes, each account generates a single active API key that replaces the previous one upon regeneration. Use standard Bearer token authentication in your headers to secure your integration against unauthorized access.

Claim your API key

Register, retrieve your key, and update your base URL. That’s it.