Search...
Menu

Text Completion (OpenAI)

Continue text from a prompt. For chat conversations, use Chat Completions rather than sending messages directly to this endpoint.

Request

Item Description
Method POST
Path /v1/completions
Gateway URL https://ailink.nativex.com
Authentication Authorization: Bearer sk-xxxx; replace the placeholder with your API Key
Request format application/json

Replace MODEL_ID with a model from the Model Marketplace that supports this endpoint. Available models, parameters, and permissions depend on your account.

Parameters

Parameter Location Type Required Description
model Body string Yes A model that supports legacy Completions
prompt Body string / string[] Yes Input prompt
max_tokens Body integer No Positive integer limiting output tokens
temperature Body number No Sampling temperature; allowed values depend on the model
top_p Body number No Nucleus sampling parameter
stream Body boolean No Whether to enable SSE
stop Body string / string[] No Stop sequences
n Body integer No Number of candidates. Start with 1; the supported range depends on the model.
echo Body boolean No Whether to echo the input; requires model support
suffix Body string No Suffix after the completion; requires model support

Example

curl -X POST 'https://ailink.nativex.com/v1/completions' \
  -H 'Authorization: Bearer sk-xxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL_ID",
  "prompt": "Continue this sentence: The first rays of morning sunlight",
  "max_tokens": 128
}'

Response

The following is a simplified response for readability. IDs, URLs, text, and usage values are illustrative.

{
  "id": "cmpl_example",
  "object": "text_completion",
  "choices": [
    {
      "text": "lit up the desk by the window.",
      "index": 0,
      "finish_reason": "stop"
    }
  ]
}
Field or result Description
choices[].text Completed text
choices[].finish_reason Reason generation stopped

Error handling

For unsuccessful responses, check the HTTP status and error body first. Verify the API Key, model name, account balance, and parameters. If rate limited, reduce concurrency and retry later.

Last modified: 2026-11-17