> ## Documentation Index
> Fetch the complete documentation index at: https://nusabase-a8dcf793.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# First Request Example

> Run a minimal working call from model listing to your first Chat Completions request.

This page shows the shortest practical call flow: verify your API key first, then send your first model request. The examples use the standard OpenAI-compatible entry point, which is the recommended starting point for new integrations, backend services, and command-line debugging.

Before you start, prepare:

| Item | Example | Notes |
| - | - | - |
| API Base URL | `https://api.nusabasedigital.com` | The English docs use this domain in examples. |
| API Key | `sk-your_api_key` | Send it as a Bearer token in the request header. |
| Model | `qwen3.5-flash` | This example model appears in the current pricing docs. Use `GET /v1/models` as the source of truth for your account. |

If you are not sure which header to use, read [Authentication](https://nusabase-a8dcf793.mintlify.site/en/getting-started/authentication.md) first.

## 1. Set Environment Variables

Put the base URL and API key into environment variables so the following examples can be copied directly.

```bash theme={null}
export NUSABASE_BASE_URL="https://api.nusabasedigital.com"
export NUSABASE_API_KEY="sk-your_api_key"
```

Windows PowerShell:

```powershell theme={null}
$env:NUSABASE_BASE_URL = "https://api.nusabasedigital.com"
$env:NUSABASE_API_KEY = "sk-your_api_key"
```

## 2. List Models

Start with `GET /v1/models`. This does not generate model output, so it is the safest first call for checking your API key, account status, and available models.

```bash theme={null}
curl "$NUSABASE_BASE_URL/v1/models" \
  -H "Authorization: Bearer $NUSABASE_API_KEY"
```

If the request succeeds, the response contains the models your account can access. Choose the `model` value in later requests from this response.

You can also retrieve one model:

```bash theme={null}
curl "$NUSABASE_BASE_URL/v1/models/qwen3.5-flash" \
  -H "Authorization: Bearer $NUSABASE_API_KEY"
```

If this step fails, start with these checks:

| Status | Common cause | What to check |
| - | - | - |
| `401` | Missing, invalid, expired, or exhausted API key | Check `Authorization: Bearer ...` and make sure you are using an API key. |
| `403` | Account, group, IP allowlist, or API access permission is not valid for the request | Check account status, key permissions, group access, and IP restrictions. |
| `503` | The selected model or channel is temporarily unavailable | Retry later or use another model returned by the model list. |

## 3. Send Your First Chat Request

Use `POST /v1/chat/completions` for the first inference request. It follows the OpenAI Chat Completions shape and has a small, easy-to-debug request body.

```bash theme={null}
curl "$NUSABASE_BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $NUSABASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.5-flash",
    "messages": [
      {
        "role": "system",
        "content": "You are a concise and accurate assistant."
      },
      {
        "role": "user",
        "content": "Introduce Nusabase API in one sentence."
      }
    ]
  }'
```

Request body fields:

| Field | Required | Description |
| - | - | - |
| `model` | Yes | The model to call. Prefer a model returned by `GET /v1/models`. |
| `messages` | Yes | Conversation message array, usually with `system`, `user`, and `assistant` roles. |
| `role` | Yes | Message role. The first user input should use `user`. |
| `content` | Yes | Message content. Text models can use a plain string. |

A successful response usually contains `choices`; the model output is in `choices[0].message.content`.

```json theme={null}
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Nusabase API is an aggregation platform for calling multiple AI models through compatible APIs."
      }
    }
  ]
}
```

> [!NOTE]
>
> The sample response only shows the key fields. Real responses may also include `id`, `object`, `created`, `model`, `usage`, and other fields.

## 4. Enable Streaming

Set `stream` to `true` if you want to receive tokens as they are generated.

```bash theme={null}
curl "$NUSABASE_BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $NUSABASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.5-flash",
    "stream": true,
    "messages": [
      {
        "role": "user",
        "content": "Give me a three-point summary."
      }
    ]
  }'
```

Streaming is useful for chat UIs, long generation tasks, and any workflow that should show the first output quickly. Your client should read the response incrementally using Server-Sent Events or a compatible streaming parser.

## 5. Responses Example

If your client already targets the OpenAI Responses style, call `POST /v1/responses`.

```bash theme={null}
curl "$NUSABASE_BASE_URL/v1/responses" \
  -H "Authorization: Bearer $NUSABASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.5-flash",
    "input": "Introduce Nusabase API in one sentence."
  }'
```

The project also exposes a context-compaction endpoint:

```bash theme={null}
curl "$NUSABASE_BASE_URL/v1/responses/compact" \
  -H "Authorization: Bearer $NUSABASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.5-flash",
    "input": "Compact this conversation context."
  }'
```

Whether a model supports Responses or compaction depends on the available backend channel configuration. If the request returns a model or channel availability error, switch to a model returned by `GET /v1/models`.

## 6. Compatibility Examples

If you already have a Claude or Gemini SDK, you can use the compatible entry points for a first smoke test.

Claude Messages example:

```bash theme={null}
curl "$NUSABASE_BASE_URL/v1/messages" \
  -H "x-api-key: $NUSABASE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.5-flash",
    "max_tokens": 128,
    "messages": [
      {
        "role": "user",
        "content": "hello"
      }
    ]
  }'
```

Gemini model-list example:

```bash theme={null}
curl "$NUSABASE_BASE_URL/v1beta/models" \
  -H "x-goog-api-key: $NUSABASE_API_KEY"
```

You can also use the query-string key form:

```bash theme={null}
curl "$NUSABASE_BASE_URL/v1beta/models?key=$NUSABASE_API_KEY"
```

Compatibility entry points may use different authentication headers and response shapes from the standard `/v1/*` API. See [Compatibility Formats](https://nusabase-a8dcf793.mintlify.site/en/getting-started/compatibility.md) for details.

## 7. Next Steps

After your first request succeeds, continue with:

| Doc | Use it for |
| - | - |
| [Authentication](https://nusabase-a8dcf793.mintlify.site/en/getting-started/authentication.md) | API key, Bearer auth, Claude, Gemini, and WebSocket authentication. |
| [Models and Pricing](https://nusabase-a8dcf793.mintlify.site/en/getting-started/pricing.md) | Choosing a model and checking input, output, cache, and other prices. |
| [Billing Rules](https://nusabase-a8dcf793.mintlify.site/en/getting-started/billing-rules.md) | Understanding usage-based, per-call, duration-based, resolution-based, and tiered billing. |
| [Error Codes](https://nusabase-a8dcf793.mintlify.site/en/getting-started/error-codes.md) | Debugging failures by `HTTP status` and `error.code`. |

## References

* [Authentication](https://nusabase-a8dcf793.mintlify.site/en/getting-started/authentication.md)
* [Compatibility Formats](https://nusabase-a8dcf793.mintlify.site/en/getting-started/compatibility.md)
* [Models and Pricing](https://nusabase-a8dcf793.mintlify.site/en/getting-started/pricing.md)
* [Error Codes](https://nusabase-a8dcf793.mintlify.site/en/getting-started/error-codes.md)


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