Skip to main content

Documentation Index

Fetch the complete documentation index at: https://doc.hitopen.com/llms.txt

Use this file to discover all available pages before exploring further.

Newapi uses API tokens (Bearer tokens) to authenticate all requests. You create tokens in the console and include them in the Authorization header of every API call.

Getting your API token

1

Log in to the console

Open your Newapi instance in a browser and sign in to your account.
2

Go to Token Management

In the sidebar, click Token Management.
3

Create a token

Click New Token. Configure the following options:
FieldDescription
NameA label to identify this token (e.g., “My App”, “Production”)
QuotaOptional maximum credit limit for this token
ExpiryOptional expiration date; leave blank for no expiry
ModelsOptional allowlist of models this token can access
4

Copy and store your key

Your token starts with sk-. Copy it now — it is only shown once.

Using your token in requests

Include your token in the Authorization header of every request:
Authorization: Bearer sk-your-token-here

Example: Chat completion

curl -X POST "https://YOUR_NEWAPI_BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer sk-your-token-here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Using with the OpenAI SDK

The OpenAI Python and JavaScript SDKs work directly with Newapi. Pass your token as api_key and your Newapi URL as base_url:
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-token-here",
    base_url="https://YOUR_NEWAPI_BASE_URL/v1"
)

Management API authentication

The Management API (for token management, channel configuration, etc.) uses a different authentication mechanism. You have two options:

Required header for some endpoints

Some management endpoints require you to identify the acting user:
New-Api-User: {user_id}
The user_id must match your currently authenticated account.

Permission levels

Management API endpoints have different permission requirements:
LevelDescription
PublicNo authentication required
UserRequires a valid API token or session
AdminRequires administrator privileges
RootHighest privilege level
For AI Model API calls (/v1/chat/completions, /v1/images/generations, etc.), always use your sk- token created in Token Management — not a system access token.

Common authentication errors

ErrorCauseFix
401 UnauthorizedMissing or invalid tokenCheck your Authorization header
403 ForbiddenToken lacks required permissionsEnsure your token has the needed quota or model access
429 Too Many RequestsRate limit or quota exceededCheck your token’s quota in Token Management