curl --request POST \
--url https://api.hopscotchlabs.ai/v1/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-4o-mini",
"prompt": "Say hi in five words."
}
'import requests
url = "https://api.hopscotchlabs.ai/v1/completions"
payload = {
"model": "openai/gpt-4o-mini",
"prompt": "Say hi in five words."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'openai/gpt-4o-mini', prompt: 'Say hi in five words.'})
};
fetch('https://api.hopscotchlabs.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://api.hopscotchlabs.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",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'openai/gpt-4o-mini',
'prompt' => 'Say hi in five words.'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.hopscotchlabs.ai/v1/completions"
payload := strings.NewReader("{\n \"model\": \"openai/gpt-4o-mini\",\n \"prompt\": \"Say hi in five words.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.hopscotchlabs.ai/v1/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"openai/gpt-4o-mini\",\n \"prompt\": \"Say hi in five words.\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.hopscotchlabs.ai/v1/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"openai/gpt-4o-mini\",\n \"prompt\": \"Say hi in five words.\"\n}"
response = http.request(request)
puts response.read_bodyCreate a text completion
Send an OpenAI text completion request, the older format that takes a prompt rather than messages. Set stream: true for server-sent events.
The body is forwarded as you sent it, so a field this page does not name still reaches the provider, and the reply is the provider’s text completion object.
On the platform’s own provider keys this route applies the same refusals as chat completions. See the 400 response. A request served on your own provider key keeps every one of those fields.
Credit is held when the request is admitted and settled against the provider’s own token counts when it finishes. You are charged the provider’s rate at face value. Nothing is added per request.
To read back the tokens and charge of one request afterwards, send the value of the x-hopscotch-request-id response header to GET /v1/usage/{id}.
curl --request POST \
--url https://api.hopscotchlabs.ai/v1/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-4o-mini",
"prompt": "Say hi in five words."
}
'import requests
url = "https://api.hopscotchlabs.ai/v1/completions"
payload = {
"model": "openai/gpt-4o-mini",
"prompt": "Say hi in five words."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'openai/gpt-4o-mini', prompt: 'Say hi in five words.'})
};
fetch('https://api.hopscotchlabs.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://api.hopscotchlabs.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",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'openai/gpt-4o-mini',
'prompt' => 'Say hi in five words.'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.hopscotchlabs.ai/v1/completions"
payload := strings.NewReader("{\n \"model\": \"openai/gpt-4o-mini\",\n \"prompt\": \"Say hi in five words.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.hopscotchlabs.ai/v1/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"openai/gpt-4o-mini\",\n \"prompt\": \"Say hi in five words.\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.hopscotchlabs.ai/v1/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"openai/gpt-4o-mini\",\n \"prompt\": \"Say hi in five words.\"\n}"
response = http.request(request)
puts response.read_bodyAuthorizations
A workspace API key in an Authorization: Bearer header. A missing header, a scheme other than Bearer, a key of the wrong shape, and a key we reject are all 401.
Body
An OpenAI text completion request. Fields beyond the ones named here are forwarded to the provider unchanged rather than refused for being unfamiliar.
A model id in provider/model form, or profile/{identifier} for one of your workspace's routing profiles. A bare model id is refused with 400 and the code model_id_not_pinned. The catalog must list the model for completions. List what you can call with GET /v1/models.
"openai/gpt-4o-mini"
What to complete: a string, an array of strings, an array of token ids, or an array of token id arrays.
Return the reply as server-sent events instead of one JSON body.
The most output tokens you will accept. Sending it also lowers the credit held for the request while it runs. Omit it and the model's published maximum output is held instead.
x >= 1Response
The completion, in OpenAI's text completion format as the provider produced it. A response that is not streamed carries the provider's token counts in its own usage object.
When stream is true the body is text/event-stream instead, in OpenAI's own chunk format, ending with data: [DONE].