For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
跳至內容

Chat Completions API

Learn how to send text generation requests with ApiSmart's OpenAI-compatible Chat Completions API and enable streaming responses.

Use the Chat Completions API to generate text with supported ApiSmart text models.

ApiSmart provides an OpenAI-compatible Chat Completions interface, making it easier to connect applications that already use the familiar messages request format.

💬 Endpoint

Method: POST

Endpoint: /v1/chat/completions

Full URL:

https://gw.apismart.ai/v1/chat/completions

🔑 Authentication

Include your ApiSmart API Key in the Authorization header:

Authorization: Bearer <your-api-key>

For JSON requests, also include:

Content-Type: application/json

Replace <your-api-key> with your actual API Key.

🚀 Basic Request

A basic request includes a valid model ID and a messages array.

curl https://gw.apismart.ai/v1/chat/completions \
  -H "Authorization: Bearer <your-api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [
      {
        "role": "user",
        "content": "Hello! Please introduce yourself."
      }
    ]
  }'

In this example:

  • model specifies the model that processes the request.

  • messages contains the conversation input.

  • role identifies the message role.

  • content contains the text sent to the model.

🧩 Choose a Model

The model parameter must use a valid ApiSmart model ID.

For example:

To retrieve the latest model list, use:

Use the returned data[].id value as the model parameter in your request.

For available text models and model ID rules, see Models and Model IDs.

Model IDs must match exactly. Periods (.), hyphens (-), version numbers, and other characters must be entered exactly as documented.

📨 Messages

The messages field contains the conversation input sent to the selected model.

A simple request can contain a single user message:

For longer conversations, include the relevant conversation messages in the messages array.

🌊 Streaming

Chat Completions also supports streaming output.

To enable streaming, add:

Example:

With streaming enabled, the response is returned incrementally instead of waiting for the complete generation.

For an overview of standard, streaming, and asynchronous API behavior, see Response Modes.

🔄 Standard vs. Streaming

Mode
Configuration
Typical Use

Standard

Default

Short responses and simple integrations

Streaming

"stream": true

Interactive applications and longer generations

Use standard responses when you want to wait for the complete result.

Use streaming when you want generated content to arrive progressively.

⚠️ Common Issues

Invalid API Key

If authentication fails, the API may return:

401 invalid_api_key

Check that:

  • The API Key is correct

  • The key is enabled

  • The Authorization header uses the Bearer scheme

  • There are no missing characters or extra spaces

Model Not Available

If the selected model is not available to your API Key, the API may return:

403 model_not_allowed

Choose another available model or contact ApiSmart Support if you need access.

Unexpected 503

If you receive an unexpected 503, first verify the model ID.

ApiSmart model IDs are matched exactly, so an incorrect period, hyphen, or version number can cause the request to fail.

For complete error information, see HTTP Status Codes and API Errors.

✅ Before Sending a Request

Before making a Chat Completions request, verify that:

  • Your API Key is valid and enabled

  • Your account has sufficient balance

  • The endpoint is /v1/chat/completions

  • Content-Type is application/json

  • The model ID is correct

  • The request includes a messages array

  • "stream": true is included only when streaming is required

➡️ Next Steps

Continue with:

最後更新於

這有幫助嗎?