Skip to content

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/completions

Request Body

ParameterTypeRequiredDescription
modelstringYesModel ID
promptstring/arrayYesThe prompt to complete
max_tokensintegerNoMaximum tokens to generate. Default: 16
temperaturenumberNoSampling temperature (0-2). Default: 1
top_pnumberNoNucleus sampling. Default: 1
nintegerNoNumber of completions. Default: 1
streambooleanNoEnable streaming. Default: false
stopstring/arrayNoStop sequences
suffixstringNoText to append after the completion
echobooleanNoEcho 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)

3xCoder — Unified AI API Endpoint