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

# API Call Examples

> We support API calls for various models. With just one Key, you can use all major AIs, saving the trouble of maintaining multiple API Keys. At the same time, we insist on providing lower prices than official

## Domains & Authentication

<Tip>
  Note: The following examples need to replace the Authorization with the actual Login Code
</Tip>

<Tip>
  Primary domain: `https://ai.liaobots.work`<br />
  Backup domains: `https://ai.liaobots1.work`, `https://ai.liaobots2.work`, `https://ai.liaobots3.work`<br />
  Keep the same path suffix when switching domains, such as `/v1` or `/v1beta`
</Tip>

## Check Balance

Query remaining credits for your auth code.

The following two paths are equivalent — use either one: `/api/v1/credits` or `/v1/credits`.

```shell Curl theme={null}
curl 'https://ai.liaobots.work/api/v1/credits' \
  -H 'Authorization: Bearer <authcode>'

# Equivalent
curl 'https://ai.liaobots.work/v1/credits' \
  -H 'Authorization: Bearer <authcode>'
```

Response:

```json theme={null}
{
  "data": {
    "balance": 85.5,
    "amount": 100.0
  }
}
```

| Field     | Description                 |
| --------- | --------------------------- |
| `balance` | Remaining available credits |
| `amount`  | Total credits received      |

### Check Credit Usage Records

Add `include_usage=true` to the balance endpoint to return detailed credit usage records. Use `pageSize` to control page size, and pass the returned `nextId` to fetch the next page.

```shell Curl theme={null}
curl 'https://ai.liaobots.work/api/v1/credits?include_usage=true&pageSize=50' \
  -H 'Authorization: Bearer <authcode>'
```

Response:

```json theme={null}
{
  "data": {
    "balance": 85.5,
    "amount": 100.0,
    "usage": {
      "pageSize": 50,
      "nextId": "1234567890",
      "list": [
        {
          "id": 1234567891,
          "tokens": 1200,
          "input_tokens": 800,
          "output_tokens": 400,
          "model": "gpt-5.4",
          "price": 0.12,
          "cache_hit_tokens": 0,
          "cache_creation_tokens": 0,
          "create_time": 1760000000000
        }
      ]
    }
  }
}
```

| Field                                | Description                                                     |
| ------------------------------------ | --------------------------------------------------------------- |
| `usage.pageSize`                     | Page size returned by this request                              |
| `usage.nextId`                       | Cursor for the next page. Empty means there are no more records |
| `usage.list[].model`                 | Model or service used                                           |
| `usage.list[].price`                 | Credits charged for this record                                 |
| `usage.list[].tokens`                | Total token count                                               |
| `usage.list[].input_tokens`          | Input token count                                               |
| `usage.list[].output_tokens`         | Output token count                                              |
| `usage.list[].cache_hit_tokens`      | Cache hit token count                                           |
| `usage.list[].cache_creation_tokens` | Cache creation token count                                      |
| `usage.list[].create_time`           | Charge time as a Unix millisecond timestamp                     |

## OpenAI Format (Chat Completions)

### Streaming Response

<CodeGroup>
  ```shell Curl theme={null}
  curl --location 'https://ai.liaobots.work/v1/chat/completions' \
  --header 'Authorization: Bearer <authcode>' \
  --header 'Content-Type: application/json' \
  --data '{
      "model": "gpt-5.4",
      "messages": [
          {
              "role": "user",
              "content": "Hi"
          }
      ],
      "temperature": 1,
      "stream": true
  }'
  ```

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

  client = OpenAI(
      api_key='authcode',
      base_url='https://ai.liaobots.work/v1'
  )


  stream = client.chat.completions.create(
      model="gpt-5.4",
      messages=[
          {
              "role": "user",
              "content": "Hi"
          }
      ],
      stream=True,
  )


  for event in stream:
      if event.choices[0].delta.content:
          print(event.choices[0].delta.content)
  ```
</CodeGroup>

### Non-Streaming Response

<CodeGroup>
  ```shell Curl theme={null}
  curl --location 'https://ai.liaobots.work/v1/chat/completions' \
  --header 'Authorization: Bearer <authcode>' \
  --header 'Content-Type: application/json' \
  --data '{
      "model": "gpt-5.4",
      "messages": [
          {
              "role": "user",
              "content": "Hi"
          }
      ],
      "temperature": 1,
      "stream": false
  }'
  ```

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

  client = OpenAI(
      api_key='authcode',
      base_url='https://ai.liaobots.work/v1'
  )


  stream = client.chat.completions.create(
      model="gpt-5.4",
      messages=[
          {
              "role": "user",
              "content": "Hi"
          }
      ],
      stream=False,
  )


  print(stream.choices[0].message.content)
  ```
</CodeGroup>

## Claude Format (Anthropic Messages)

### Streaming Response

<CodeGroup>
  ```shell Curl theme={null}
  curl 'https://ai.liaobots.work/v1/messages' \
    -H 'x-api-key: <authcode>' \
    -H 'anthropic-version: 2023-06-01' \
    -H 'Content-Type: application/json' \
    -d '{
      "model": "claude-sonnet-4-6",
      "max_tokens": 1024,
      "stream": true,
      "messages": [
          {
              "role": "user",
              "content": "Hi"
          }
      ]
  }'
  ```

  ```python Python theme={null}
  import anthropic

  client = anthropic.Anthropic(
      api_key='authcode',
      base_url='https://ai.liaobots.work'
  )

  with client.messages.stream(
      model="claude-sonnet-4-6",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": "Hi"
          }
      ],
  ) as stream:
      for text in stream.text_stream:
          print(text, end="")
  ```
</CodeGroup>

### Non-Streaming Response

<CodeGroup>
  ```shell Curl theme={null}
  curl 'https://ai.liaobots.work/v1/messages' \
    -H 'x-api-key: <authcode>' \
    -H 'anthropic-version: 2023-06-01' \
    -H 'Content-Type: application/json' \
    -d '{
      "model": "claude-sonnet-4-6",
      "max_tokens": 1024,
      "messages": [
          {
              "role": "user",
              "content": "Hi"
          }
      ]
  }'
  ```

  ```python Python theme={null}
  import anthropic

  client = anthropic.Anthropic(
      api_key='authcode',
      base_url='https://ai.liaobots.work'
  )

  message = client.messages.create(
      model="claude-sonnet-4-6",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": "Hi"
          }
      ],
  )

  print(message.content[0].text)
  ```
</CodeGroup>

## OpenAI Responses API

### Streaming Response

<CodeGroup>
  ```shell Curl theme={null}
  curl 'https://ai.liaobots.work/v1/responses' \
    -H 'Authorization: Bearer <authcode>' \
    -H 'Content-Type: application/json' \
    -d '{
      "model": "gpt-5.4",
      "stream": true,
      "input": "Hi"
  }'
  ```

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

  client = OpenAI(
      api_key='authcode',
      base_url='https://ai.liaobots.work/v1'
  )

  stream = client.responses.create(
      model="gpt-5.4",
      input="Hi",
      stream=True,
  )

  for event in stream:
      if hasattr(event, 'delta') and event.delta:
          print(event.delta, end="")
  ```
</CodeGroup>

### Non-Streaming Response

<CodeGroup>
  ```shell Curl theme={null}
  curl 'https://ai.liaobots.work/v1/responses' \
    -H 'Authorization: Bearer <authcode>' \
    -H 'Content-Type: application/json' \
    -d '{
      "model": "gpt-5.4",
      "input": "Hi"
  }'
  ```

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

  client = OpenAI(
      api_key='authcode',
      base_url='https://ai.liaobots.work/v1'
  )

  response = client.responses.create(
      model="gpt-5.4",
      input="Hi",
  )

  print(response.output_text)
  ```
</CodeGroup>

## Gemini Format (Gemini Native)

### Non-Streaming Response

```shell Curl theme={null}
curl "https://ai.liaobots.work/v1beta/models/gemini-3-pro-preview(or other models):generateContent" \
  -H "x-goog-api-key: <authcode>" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [
      {
        "role": "system",
        "parts": [
          {
            "text": "You are a helpful assistant. Reply in Chinese."
          }
        ]
      },
      {
        "role": "user",
        "parts": [
          {
            "text": "Explain how AI works in a few words"
          }
        ]
      }
    ]
  }'
```

### Streaming Response

```shell Curl theme={null}
curl "https://ai.liaobots.work/v1beta/models/gemini-3-pro-preview(or other models):streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: <authcode>" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [
      {
        "role": "system",
        "parts": [
          {
            "text": "You are a helpful assistant. Reply in Chinese."
          }
        ]
      },
      {
        "role": "user",
        "parts": [
          {
            "text": "Explain how AI works in a few words"
          }
        ]
      }
    ]
  }'
```

## Gemini Nano Banana 2/Pro

### Non-Streaming Response

```shell Curl theme={null}
curl "https://ai.liaobots.work/v1beta/models/gemini-3-pro-image-preview:generateContent" \
  -H "x-goog-api-key: <authcode>" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
      "contents": [
          {
              "parts": [
                  {
                      "text": "Generate a visualization of the current weather in Tokyo."
                  }
              ]
          }
      ],
      "tools": [
          {
              "googleSearch": {}
          }
      ],
      "generationConfig": {
          "imageConfig": {
              "aspectRatio": "1:1",
              "imageSize": "2K"
          },
          "responseModalities":
          [
              "TEXT",
              "IMAGE"
          ]
      }
  }
```

### Streaming Response

```shell Curl theme={null}
curl "https://ai.liaobots.work/v1beta/models/gemini-3-pro-image-preview:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: <authcode>" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
      "contents": [
          {
              "parts": [
                  {
                      "text": "Generate two dogs in manga style."
                  }
              ]
          }
      ],
      "generationConfig": {
          "imageConfig": {
              "aspectRatio": "16:9",
              "imageSize": "1K"
          },
          "responseModalities":
          [
              "TEXT",
              "IMAGE"
          ]
      }
  }
```
