Skip to main content
POST
/
v1
/
completions
Completions (legacy)
curl --request POST \
  --url https://openp.ai/v1/completions
import requests

url = "https://openp.ai/v1/completions"

response = requests.post(url)

print(response.text)
const options = {method: 'POST'};

fetch('https://openp.ai/v1/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://openp.ai/v1/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"net/http"
"io"
)

func main() {

url := "https://openp.ai/v1/completions"

req, _ := http.NewRequest("POST", url, nil)

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://openp.ai/v1/completions")
.asString();
require 'uri'
require 'net/http'

url = URI("https://openp.ai/v1/completions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
The legacy text completion endpoint, mainly for backward compatibility. For new projects, use Chat Completions.

Request

curl https://openp.ai/v1/completions \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Once upon a time",
    "max_tokens": 64,
    "temperature": 0.7
  }'

Main parameters

FieldTypeDescription
modelstringModel ID (a few models like gpt-3.5-turbo-instruct support this)
promptstring | arrayThe input prompt
max_tokensintegerMaximum output
temperature / top_pnumberSampling
nintegerNumber of candidates
streambooleanSSE stream
stopstring | arrayStop sequences
presence_penalty / frequency_penaltynumberPenalties
echobooleanInclude the prompt in the output
best_ofintegerGenerate several server-side and pick the best
logprobsintegerReturn logprobs

Response

{
  "id": "cmpl-...",
  "object": "text_completion",
  "created": 1715750400,
  "model": "gpt-3.5-turbo-instruct",
  "choices": [
    {
      "text": ", there was a small castle...",
      "index": 0,
      "logprobs": null,
      "finish_reason": "length"
    }
  ],
  "usage": {"prompt_tokens": 4, "completion_tokens": 64, "total_tokens": 68}
}

Migrating to Chat

Change prompt to messages:
- "prompt": "Once upon a time"
+ "messages": [{"role": "user", "content": "Continue: Once upon a time"}]
And switch the model ID to something like gpt-5.5.