Appearance
Completions
Create a text completion using the specified model. This is the legacy completions endpoint.
TIP
For most use cases, use the Chat Completions endpoint instead. It supports all modern models and provides a more flexible interface.
Create Completion
POST https://api.3xcoder.com/v1/completionsRequest Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID |
prompt | string/array | Yes | The prompt to complete |
max_tokens | integer | No | Maximum tokens to generate. Default: 16 |
temperature | number | No | Sampling temperature (0-2). Default: 1 |
top_p | number | No | Nucleus sampling. Default: 1 |
n | integer | No | Number of completions. Default: 1 |
stream | boolean | No | Enable streaming. Default: false |
stop | string/array | No | Stop sequences |
suffix | string | No | Text to append after the completion |
echo | boolean | No | Echo the prompt in the response. Default: false |
Response
json
{
"id": "cmpl-abc123",
"object": "text_completion",
"created": 1700000000,
"model": "gpt-3.5-turbo-instruct",
"choices": [
{
"text": "\n\nThis is a test completion.",
"index": 0,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 7,
"total_tokens": 12
}
}Examples
bash
curl https://api.3xcoder.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "Write a tagline for an AI company:",
"max_tokens": 50,
"temperature": 0.7
}'python
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://api.3xcoder.com/v1"
)
response = client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt="Write a tagline for an AI company:",
max_tokens=50,
temperature=0.7
)
print(response.choices[0].text)javascript
const response = await fetch('https://api.3xcoder.com/v1/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`
},
body: JSON.stringify({
model: 'gpt-3.5-turbo-instruct',
prompt: 'Write a tagline for an AI company:',
max_tokens: 50,
temperature: 0.7
})
})
const data = await response.json()
console.log(data.choices[0].text)