Skip to main content
POST
/
sdk
/
v1
/
prompts
/
{id}
/
completion
JavaScript
import PromptFoundry from '@prompt-foundry/typescript-sdk';

const client = new PromptFoundry({
  apiKey: process.env['PROMPT_FOUNDRY_API_KEY'], // This is the default and can be omitted
});

async function main() {
  const completionCreateResponse = await client.completion.create('1212121');

  console.log(completionCreateResponse.provider);
}

main();
import os
from prompt_foundry_python_sdk import PromptFoundry

client = PromptFoundry(
# This is the default and can be omitted
api_key=os.environ.get("PROMPT_FOUNDRY_API_KEY"),
)
completion_create_response = client.completion.create(
id="1212121",
)
print(completion_create_response.provider)
curl --request POST \
--url https://api.promptfoundry.ai/sdk/v1/prompts/{id}/completion \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"variables": {},
"overrideMessages": [
{
"content": [
{
"type": "TEXT",
"text": "<string>"
}
]
}
],
"appendMessages": [
{
"content": [
{
"type": "TEXT",
"text": "<string>"
}
]
}
],
"user": "<string>"
}
'
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.promptfoundry.ai/sdk/v1/prompts/{id}/completion",
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([
'variables' => [

],
'overrideMessages' => [
[
'content' => [
[
'type' => 'TEXT',
'text' => '<string>'
]
]
]
],
'appendMessages' => [
[
'content' => [
[
'type' => 'TEXT',
'text' => '<string>'
]
]
]
],
'user' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);

$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.promptfoundry.ai/sdk/v1/prompts/{id}/completion"

payload := strings.NewReader("{\n \"variables\": {},\n \"overrideMessages\": [\n {\n \"content\": [\n {\n \"type\": \"TEXT\",\n \"text\": \"<string>\"\n }\n ]\n }\n ],\n \"appendMessages\": [\n {\n \"content\": [\n {\n \"type\": \"TEXT\",\n \"text\": \"<string>\"\n }\n ]\n }\n ],\n \"user\": \"<string>\"\n}")

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

req.Header.Add("X-API-KEY", "<api-key>")
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.promptfoundry.ai/sdk/v1/prompts/{id}/completion")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"variables\": {},\n \"overrideMessages\": [\n {\n \"content\": [\n {\n \"type\": \"TEXT\",\n \"text\": \"<string>\"\n }\n ]\n }\n ],\n \"appendMessages\": [\n {\n \"content\": [\n {\n \"type\": \"TEXT\",\n \"text\": \"<string>\"\n }\n ]\n }\n ],\n \"user\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.promptfoundry.ai/sdk/v1/prompts/{id}/completion")

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

request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"variables\": {},\n \"overrideMessages\": [\n {\n \"content\": [\n {\n \"type\": \"TEXT\",\n \"text\": \"<string>\"\n }\n ]\n }\n ],\n \"appendMessages\": [\n {\n \"content\": [\n {\n \"type\": \"TEXT\",\n \"text\": \"<string>\"\n }\n ]\n }\n ],\n \"user\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "name": "<string>",
  "stats": {
    "inputTokenCount": 123,
    "outputTokenCount": 123,
    "latency": 123,
    "cost": 123
  },
  "message": {
    "content": [
      {
        "type": "TEXT",
        "text": "<string>"
      }
    ]
  }
}
{
"error": "<string>"
}
{
"error": "<string>"
}
{
"error": "<string>"
}
{
"error": "<string>"
}

Authorizations

X-API-KEY
string
header
required

Path Parameters

id
string
required
Example:

"1212121"

Body

application/json
variables
object

The template variables added to the prompt when executing the prompt.

overrideMessages
object[]

Replaces the configured prompt messages when running the prompt.

appendMessages
object[]

Appended the the end of the configured prompt messages before running the prompt.

user
string

A unique identifier representing your end-user, which can help monitor and detect abuse.

Response

Successful completion response

provider
enum<string>
required

The provider of the provided model.

Available options:
ANTHROPIC,
OPENAI
name
string
required
stats
object
required
message
object
required

The completion message generated by the model.