> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sinarcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI API overview

> Call many AI models through one OpenAI-compatible endpoint, authenticate with API keys, and pay per token from your prepaid rupiah balance.

The SinarCloud AI API lets you call many AI models through one endpoint that works with OpenAI SDKs and tools. You authenticate with API keys that you create in the console. You pay per token from the same prepaid rupiah balance that pays for your servers.

## How the API works

The API follows the OpenAI API format. To move existing OpenAI code to SinarCloud, you change three settings: the base URL, the API key and the model alias.

The base URL is `https://ai.sinarcloud.com/v1`. These endpoints are available under it:

| Method and path | Use it for |
| - | - |
| `POST /chat/completions` | Chat and assistant replies from a list of messages |
| `POST /completions` | Complete a single text prompt |
| `POST /embeddings` | Turn text into vectors for search and similarity |
| `POST /responses`, `POST /responses/compact` | Requests in the OpenAI Responses API format |
| `GET /models`, `GET /models/MODEL_ALIAS` | List the models you can call, or get details for one |

Each model supports only some of these endpoints. The [Models](https://docs.sinarcloud.com/ai/models.md) page shows each model's capabilities, prices and model alias. Streaming responses are supported. Errors use the OpenAI error format. For examples and error codes, see [Send requests](https://docs.sinarcloud.com/ai/requests.md).

Your account can have only a limited number of requests in progress at once. Extra requests fail with HTTP status `429` and the code `rate_limit_exceeded`. Retry when an earlier request finishes.

## Authentication

Send your API key as a bearer token in the `Authorization` header:

```text theme={null}
Authorization: Bearer YOUR_API_KEY
```

Only SinarCloud API keys work. A key from OpenAI or any other service fails with the code `invalid_api_key`. You create and revoke keys on the [API keys](https://docs.sinarcloud.com/ai/api-keys.md) page. A key stops working when you revoke it or when it expires.

## How you pay

* Each model has its own price per 1M tokens, with separate prices for input and output tokens. Some models also have prices for reading from and writing to the prompt cache. See [Models and pricing](https://docs.sinarcloud.com/ai/models.md).
* Promotions and new-signup offers can lower a model's price. When a promotion applies to you, the prices on the Models page include it. The price and promotion in effect when a request starts apply to that request. If a promotion has a spending limit and the limit runs out before the request finishes, the promotion may discount less.
* You are charged after a request finishes, for the tokens it used. The charge is deducted from your balance automatically.
* If you have [token credits](https://docs.sinarcloud.com/ai/token-credits.md) for the model, they pay for the request's tokens before your balance does. Your balance pays only for the rest. Requests under a 100% promotion don't use your token credits while the promotion covers them.
* If your balance is zero or negative and you have no token credits for the model, new requests to that model fail with HTTP status `402` and the code `insufficient_balance`. Requests that can't cost you anything, such as requests under a 100% promotion, still work. [Add balance](https://docs.sinarcloud.com/billing/top-up.md) to continue.
* Because the charge comes after the request, a request can take your balance below zero. Your next top-up covers the negative amount first.

Your balance shows as **Current Credits** on the **Billing** page, under **Account** in the console sidebar. To see what your AI requests cost, click **Usage** under **AI**. See [Usage and spending](https://docs.sinarcloud.com/ai/usage.md).

> [!WARNING]
>
> AI usage and VPS renewals draw from the same balance. If AI usage leaves too little balance when a server renews automatically, the renewal fails, and the server and its data are deleted shortly after its billing period ends. See [Renewals and expiry](https://docs.sinarcloud.com/vps/renewals.md).

## Connect your code

The base URL is `https://ai.sinarcloud.com/v1`. Store your API key in an environment variable. See [API keys](https://docs.sinarcloud.com/ai/api-keys.md).

> [tab] macOS and Linux
>
> ```bash theme={null}
> export SINARCLOUD_API_KEY="YOUR_API_KEY"
> ```

> [tab] Windows PowerShell
>
> ```powershell theme={null}
> $env:SINARCLOUD_API_KEY = "YOUR_API_KEY"
> ```

For Python, install the OpenAI SDK with `pip install openai`. Then pass the three settings to the client. The example uses `deepseek/deepseek-v4-1-flash`. To call another chat model, replace it with that model's alias. To copy an alias, click the copy icon next to it on the [Models](https://docs.sinarcloud.com/ai/models.md) page.

```python theme={null}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://ai.sinarcloud.com/v1",
    api_key=os.environ["SINARCLOUD_API_KEY"],
)

response = client.chat.completions.create(
    model="deepseek/deepseek-v4-1-flash",
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
```

For a step-by-step walkthrough, see [Make your first AI request](https://docs.sinarcloud.com/ai-quickstart.md).

## Next steps

> [card] [Make your first AI request](https://docs.sinarcloud.com/ai-quickstart.md)
>
> Create a key and send a request in a few minutes.

> [card] [Models and pricing](https://docs.sinarcloud.com/ai/models.md)
>
> Compare models, capabilities and prices per 1M tokens.

> [card] [API keys](https://docs.sinarcloud.com/ai/api-keys.md)
>
> Create, rename and revoke the keys your apps use.

> [card] [Send requests](https://docs.sinarcloud.com/ai/requests.md)
>
> Call each endpoint and handle errors.

> [card] [Playground](https://docs.sinarcloud.com/ai/playground.md)
>
> Try a model from the console before you write code.

> [card] [Usage and spending](https://docs.sinarcloud.com/ai/usage.md)
>
> Review requests, tokens and charges in detail.

> [card] [Token credits](https://docs.sinarcloud.com/ai/token-credits.md)
>
> See prepaid tokens per model and when they expire.

> [card] [Add balance](https://docs.sinarcloud.com/billing/top-up.md)
>
> Top up the balance that pays for AI and VPS.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.