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/jsonReplace <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:
modelspecifies the model that processes the request.messagescontains the conversation input.roleidentifies the message role.contentcontains 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
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
Authorizationheader uses theBearerschemeThere 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/completionsContent-Typeisapplication/jsonThe model ID is correct
The request includes a
messagesarray"stream": trueis included only when streaming is required
➡️ Next Steps
Continue with:
Models and Model IDs — Find supported text model IDs
Model Pricing and Billing — Understand model-specific billing
Response Modes — Understand standard, streaming, and asynchronous responses
Usage Logs and Costs — Review request usage and costs
HTTP Status Codes and API Errors — Troubleshoot API failures
最後更新於
這有幫助嗎?