Main site
Getting started

API Getting Started

Prepare an API Key, send your first request, understand the response, and check usage records.

Prepare an API Key and model name in the console, send your first request from an API client, then check usage records. This page contains examples and does not make API calls.

1. Prepare your request

Choose an active API Key, check its groups and model restrictions, and obtain the API address provided by the platform.

  1. Open API Keys and create or choose an enabled Key.
  2. Find the model name in the model catalog and check that the Key's groups and model restrictions allow it.
  3. Use the platform's Base URL in your API client to send the non-streaming request below.
  4. After the request, find its usage record by time, status, model, and Key suffix.

2. Send the first request from your API client

Replace BASE_URL with the platform's API address, including /v1. Replace API_KEY with your Key and MODEL_ID with the model name, removing the surrounding angle brackets from each placeholder.

curl --request POST '<BASE_URL>/chat/completions' \
  --header 'Authorization: Bearer <API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "<MODEL_ID>",
    "messages": [
      { "role": "user", "content": "Reply with a short connection confirmation." }
    ],
    "stream": false
  }'

Replace these example values in your own client. Keep real Keys out of code repositories, chats, and shell history.

3. Read the response

A successful call requires HTTP 200, parseable JSON, object = chat.completion, and a non-empty choices0.message.content.

{
  "id": "<COMPLETION_ID>",
  "object": "chat.completion",
  "created": 0,
  "model": "<MODEL_ID>",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "<MODEL_OUTPUT>" },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0
  }
}

The JSON below illustrates the response structure. Check the actual HTTP status and content returned by your request.

Failures use the standard OpenAI-compatible error envelope:

{
  "error": {
    "message": "<USER_VISIBLE_MESSAGE>",
    "type": "<ERROR_TYPE>",
    "param": "<RELATED_PARAMETER_OR_NULL>",
    "code": "<ERROR_CODE>"
  }
}
HTTP statusMeaningNext action
400The JSON, model, or request fields are invalidCheck the request body, model name, and error.param/code.
401Bearer authentication is missing, malformed, or unusableCheck the Authorization header and Key status. Never send the full Key to support.
403The Key cannot use the selected model, group, or sourceCheck the Key's groups, model restrictions, and source restrictions.
429Quota, budget, or rate limiting rejected the callRead error.code and Retry-After when present. Stop immediate retries.
422The server could not process the requestCorrect the request using error.message and the relevant fields.
503The service is temporarily unavailableKeep the time and error code, then retry later or contact support.
No HTTP responseThe request outcome is unknownCheck Console request history first. Do not immediately replay a request that may be billable.

4. Check usage records

  1. Open usage records and select a time range covering your request.
  2. Find the record by time, status, model, and Key suffix, without entering the secret again.
  3. Compare its status, model, Key suffix, and timestamp with the request you sent.
  4. Records may appear after a short delay. Keep the response and refresh manually; do not resend a request just because the list is temporarily empty.
If the outcome is unknown, check records first
A lost connection does not mean the request was never processed. Check usage records before retrying. If records are unavailable, keep the response and timestamp and confirm the outcome after recovery to avoid duplicate charges.

Protect your API Key

  • Use the Key only in your own API client. This page does not read or store it.
  • Keep Keys out of URLs, public pages, and code repositories.
  • Remove Keys, Authorization headers, cookies, and other credentials before sharing screenshots, logs, or troubleshooting details.
  • If a Key may have leaked, disable or delete it in the console and update your client with a replacement.

© 2026 Code4AI · code4ai.top