Completions
The legacy text completion endpoint generates text from an input prompt.
Recommendation
For most conversational use cases, use the Chat API. It supports multi-turn conversations and provides more complete functionality.
Create a completion
http
POST https://api.nexusmodels.cn/v1/completionsRequest parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID |
prompt | string/array | Yes | Input prompt |
suffix | string | No | Text appended after the generated content |
max_tokens | integer | No | Maximum number of generated tokens |
temperature | number | No | Sampling temperature, usually between 0 and 2 |
top_p | number | No | Nucleus sampling value, usually between 0 and 1 |
n | integer | No | Number of completion candidates to return |
stream | boolean | No | Enables streaming output |
logprobs | integer | No | Number of token log probabilities to return |
echo | boolean | No | Includes the original prompt in the response |
stop | string/array | No | Sequence that stops generation |
presence_penalty | number | No | Presence penalty |
frequency_penalty | number | No | Frequency penalty |
best_of | integer | No | Generates multiple results on the server and returns the best one |
Parameter compatibility
Supported parameters may vary by model. Unsupported parameters may be ignored or cause the request to fail.
cURL example
bash
curl -sS -X POST \
'https://api.nexusmodels.cn/v1/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_NEXUSMODELS_API_KEY' \
-d '{
"model": "YOUR_COMPLETION_MODEL",
"prompt": "Write a short greeting:",
"max_tokens": 50,
"temperature": 0.7
}'Response
A successful request returns:
http
200 OKjson
{
"id": "cmpl-abc123",
"object": "text_completion",
"created": 1788163200,
"model": "YOUR_COMPLETION_MODEL",
"choices": [
{
"text": "Hello! I hope you have a wonderful and productive day.",
"index": 0,
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 18,
"total_tokens": 33
}
}Response fields
| Field | Description |
|---|---|
id | Unique identifier for the completion request |
object | Response object type |
created | Response creation timestamp |
model | Model used for the request |
choices | Completion candidates generated by the model |
choices[].text | Generated text |
choices[].index | Candidate index |
choices[].logprobs | Token log probabilities |
choices[].finish_reason | Reason generation stopped |
usage | Token usage information for the request |
Code completion example
This example requires a model that supports code completion.
bash
curl -sS -X POST \
'https://api.nexusmodels.cn/v1/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_NEXUSMODELS_API_KEY' \
-d '{
"model": "YOUR_COMPLETION_MODEL",
"prompt": "// JavaScript: calculate the sum of all even numbers in an array\nfunction sumEvenNumbers(arr) {\n",
"max_tokens": 100,
"temperature": 0.2
}'Python example
Install the dependency:
bash
pip install requestsCall the API:
python
import os
import requests