Skip to main content
POST
/
v1
/
prompt_engine
import { JigsawStack } from "jigsawstack";

const jigsaw = JigsawStack({ apiKey: "your-api-key" });

const response = await jigsaw.prompt_engine.create({
  "prompt": "Tell me a story about {about}",
  "inputs": [
        {
              "key": "about",
              "optional": false,
              "initial_value": "Leaning Tower of Pisa"
        }
  ],
  "return_prompt": "Return the result in a markdown format",
  "prompt_guard": [
        "sexual_content",
        "defamation"
  ]
})
from jigsawstack import JigsawStack

jigsaw = JigsawStack(api_key="your-api-key")

response = jigsaw.prompt_engine.create({
  "prompt": "Tell me a story about {about}",
  "inputs": [
        {
              "key": "about",
              "optional": False,
              "initial_value": "Leaning Tower of Pisa"
        }
  ],
  "return_prompt": "Return the result in a markdown format",
  "prompt_guard": [
        "sexual_content",
        "defamation"
  ]
})
curl https://api.jigsawstack.com/v1/prompt_engine \
-X POST \
-H 'Content-Type: application/json' \
-H 'x-api-key: your-api-key' \
-d '{"prompt":"Tell me a story about {about}","inputs":[{"key":"about","optional":false,"initial_value":"Leaning Tower of Pisa"}],"return_prompt":"Return the result in a markdown format","prompt_guard":["sexual_content","defamation"]}'
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.jigsawstack.com/v1/prompt_engine');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'x-api-key: your-api-key',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"prompt":"Tell me a story about {about}","inputs":[{"key":"about","optional":false,"initial_value":"Leaning Tower of Pisa"}],"return_prompt":"Return the result in a markdown format","prompt_guard":["sexual_content","defamation"]}');

$response = curl_exec($ch);

curl_close($ch);

require 'net/http'
require 'json'

uri = URI('https://api.jigsawstack.com/v1/prompt_engine')
req = Net::HTTP::Post.new(uri)
req.content_type = 'application/json'
req['x-api-key'] = 'your-api-key'

req.body = {
'prompt' => 'Tell me a story about {about}',
'inputs' => [
{
  'key' => 'about',
  'optional' => false,
  'initial_value' => 'Leaning Tower of Pisa'
}
],
'return_prompt' => 'Return the result in a markdown format',
'prompt_guard' => [
'sexual_content',
'defamation'
]
}.to_json

req_options = {
use_ssl: uri.scheme == 'https'
}
res = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(req)
end

package main

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

func main() {
client := &http.Client{}
var data = strings.NewReader(`{"prompt":"Tell me a story about {about}","inputs":[{"key":"about","optional":false,"initial_value":"Leaning Tower of Pisa"}],"return_prompt":"Return the result in a markdown format","prompt_guard":["sexual_content","defamation"]}`)
req, err := http.NewRequest("POST", "https://api.jigsawstack.com/v1/prompt_engine", data)
if err != nil {
	log.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", "your-api-key")
resp, err := client.Do(req)
if err != nil {
	log.Fatal(err)
}
defer resp.Body.Close()
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%s\n", bodyText)
}

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.jigsawstack.com/v1/prompt_engine"))
.POST(BodyPublishers.ofString("{\"prompt\":\"Tell me a story about {about}\",\"inputs\":[{\"key\":\"about\",\"optional\":false,\"initial_value\":\"Leaning Tower of Pisa\"}],\"return_prompt\":\"Return the result in a markdown format\",\"prompt_guard\":[\"sexual_content\",\"defamation\"]}"))
.setHeader("Content-Type", "application/json")
.setHeader("x-api-key", "your-api-key")
.build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

import Foundation

let jsonData = [
"prompt": "Tell me a story about {about}",
"inputs": [
    [
        "key": "about",
        "optional": false,
        "initial_value": "Leaning Tower of Pisa"
    ]
],
"return_prompt": "Return the result in a markdown format",
"prompt_guard": [
    "sexual_content",
    "defamation"
]
] as [String : Any]
let data = try! JSONSerialization.data(withJSONObject: jsonData, options: [])

let url = URL(string: "https://api.jigsawstack.com/v1/prompt_engine")!
let headers = [
"Content-Type": "application/json",
"x-api-key": "your-api-key"
]

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = data as Data

let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if let error = error {
    print(error)
} else if let data = data {
    let str = String(data: data, encoding: .utf8)
    print(str ?? "")
}
}

task.resume()

import 'package:http/http.dart' as http;

void main() async {
final headers = {
'Content-Type': 'application/json',
'x-api-key': 'your-api-key',
};

final data = '{"prompt":"Tell me a story about {about}","inputs":[{"key":"about","optional":false,"initial_value":"Leaning Tower of Pisa"}],"return_prompt":"Return the result in a markdown format","prompt_guard":["sexual_content","defamation"]}';

final url = Uri.parse('https://api.jigsawstack.com/v1/prompt_engine');

final res = await http.post(url, headers: headers, body: data);
final status = res.statusCode;
if (status != 200) throw Exception('http.post error: statusCode= $status');

print(res.body);
}

import java.io.IOException
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody

val client = OkHttpClient()

val MEDIA_TYPE = "application/json".toMediaType()

val requestBody = "{\"prompt\":\"Tell me a story about {about}\",\"inputs\":[{\"key\":\"about\",\"optional\":false,\"initial_value\":\"Leaning Tower of Pisa\"}],\"return_prompt\":\"Return the result in a markdown format\",\"prompt_guard\":[\"sexual_content\",\"defamation\"]}"

val request = Request.Builder()
.url("https://api.jigsawstack.com/v1/prompt_engine")
.post(requestBody.toRequestBody(MEDIA_TYPE))
.header("Content-Type", "application/json")
.header("x-api-key", "your-api-key")
.build()

client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
response.body!!.string()
}

using System.Net.Http.Headers;
using System.Net.Http.Json;

HttpClient client = new HttpClient();

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://api.jigsawstack.com/v1/prompt_engine");
request.Headers.Add("x-api-key", "your-api-key");
request.Content = JsonContent.Create(new
{
prompt = "Tell me a story about {about}",
inputs = new List<object> { {"key":"about","optional":false,"initial_value":"Leaning Tower of Pisa"} },
return_prompt = "Return the result in a markdown format",
prompt_guard = new List<string> { "sexual_content", "defamation" }
});
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

HttpResponseMessage response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();

Console.WriteLine(responseBody);
{
  "success": true,
  "prompt_engine_id": "dea57da0-eea1-400f-b5df-2f6216a4c2b9",
  "optimized_prompt": "Write a detailed and engaging story about {about}, including vivid descriptions, well-developed characters, and a clear beginning, middle, and end.",
  "_usage": {
        "input_tokens": 58,
        "output_tokens": 61,
        "inference_time_tokens": 1121,
        "total_tokens": 1240
  }
}
🎉 Exciting News! We’ve enhanced Prompt Engine with powerful new capabilities. Meet Interfaze - our advanced LLM that takes your AI workflows to the next level, built for debvelopers, with improved performance better organization, and enhanced features.
x-api-key
string
required
Your JigsawStack API key

Body

name
string
Name of the prompt engine. Maximum 300 characters.
prompt
string
required
The prompt. Maximum character limit is 500000. Prompt supports dynamic inputs. See example below.
inputs
array<object>
The prompt inputs. See example below.
return_prompt
string | array | object
How the prompt result should be returned or formatted. See examples below
prompt_guard
array<string>
Include this to guard against unsafe inputs from users. Supported values:
  • defamation
  • privacy
  • hate
  • sexual_content
  • elections
  • code_interpreter_abuse
  • indiscrimate_weapons
  • specialized_advice
optimize_prompt
boolean
Include this to optimize the prompt for best results. True by default.
use_internet
boolean
Include this to allow prompt engine to use the internet.

Sample Prompt Payload

  • String return_prompt
{
    prompt: "Tell me a story about {about}",
    inputs: [
      {
        key: "about",
        optional: false,
        initial_value: "Leaning Tower of Pisa",
      },
    ],
    return_prompt: "Return the result in a markdown format",
    "prompt_guard": ["sexual_content", "defamation"]
  }
  • Array<object> return_prompt

{
    prompt: "Tell me a story about {about}",
    inputs: [
      {
        key: "about",
        optional: "false",
        initial_value: "Leaning Tower of Pisa",
      },
    ],
    return_prompt: [{ excerpt: "short story text", summary: "summary of story" }],
    "prompt_guard": ["sexual_content", "defamation"]
  }
  • Object return_prompt
{
    prompt: "Tell me a story about {about}",
    inputs: [
      {
        key: "about",
        optional: false,
        initial_value: "Leaning Tower of Pisa",
      },
    ],
    return_prompt: { excerpt: "short story text", summary: "summary of story" },
    "prompt_guard": ["sexual_content", "defamation"]
  }

Header

x-api-key
string
required
Your JigsawStack API key

Response

success
boolean
Indicates whether the call was successful.
_usage
object
Usage information for the API call.
log_id
string
A unique identifier for the request
import { JigsawStack } from "jigsawstack";

const jigsaw = JigsawStack({ apiKey: "your-api-key" });

const response = await jigsaw.prompt_engine.create({
  "prompt": "Tell me a story about {about}",
  "inputs": [
        {
              "key": "about",
              "optional": false,
              "initial_value": "Leaning Tower of Pisa"
        }
  ],
  "return_prompt": "Return the result in a markdown format",
  "prompt_guard": [
        "sexual_content",
        "defamation"
  ]
})
from jigsawstack import JigsawStack

jigsaw = JigsawStack(api_key="your-api-key")

response = jigsaw.prompt_engine.create({
  "prompt": "Tell me a story about {about}",
  "inputs": [
        {
              "key": "about",
              "optional": False,
              "initial_value": "Leaning Tower of Pisa"
        }
  ],
  "return_prompt": "Return the result in a markdown format",
  "prompt_guard": [
        "sexual_content",
        "defamation"
  ]
})
curl https://api.jigsawstack.com/v1/prompt_engine \
-X POST \
-H 'Content-Type: application/json' \
-H 'x-api-key: your-api-key' \
-d '{"prompt":"Tell me a story about {about}","inputs":[{"key":"about","optional":false,"initial_value":"Leaning Tower of Pisa"}],"return_prompt":"Return the result in a markdown format","prompt_guard":["sexual_content","defamation"]}'
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.jigsawstack.com/v1/prompt_engine');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'x-api-key: your-api-key',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"prompt":"Tell me a story about {about}","inputs":[{"key":"about","optional":false,"initial_value":"Leaning Tower of Pisa"}],"return_prompt":"Return the result in a markdown format","prompt_guard":["sexual_content","defamation"]}');

$response = curl_exec($ch);

curl_close($ch);

require 'net/http'
require 'json'

uri = URI('https://api.jigsawstack.com/v1/prompt_engine')
req = Net::HTTP::Post.new(uri)
req.content_type = 'application/json'
req['x-api-key'] = 'your-api-key'

req.body = {
'prompt' => 'Tell me a story about {about}',
'inputs' => [
{
  'key' => 'about',
  'optional' => false,
  'initial_value' => 'Leaning Tower of Pisa'
}
],
'return_prompt' => 'Return the result in a markdown format',
'prompt_guard' => [
'sexual_content',
'defamation'
]
}.to_json

req_options = {
use_ssl: uri.scheme == 'https'
}
res = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(req)
end

package main

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

func main() {
client := &http.Client{}
var data = strings.NewReader(`{"prompt":"Tell me a story about {about}","inputs":[{"key":"about","optional":false,"initial_value":"Leaning Tower of Pisa"}],"return_prompt":"Return the result in a markdown format","prompt_guard":["sexual_content","defamation"]}`)
req, err := http.NewRequest("POST", "https://api.jigsawstack.com/v1/prompt_engine", data)
if err != nil {
	log.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", "your-api-key")
resp, err := client.Do(req)
if err != nil {
	log.Fatal(err)
}
defer resp.Body.Close()
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%s\n", bodyText)
}

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.jigsawstack.com/v1/prompt_engine"))
.POST(BodyPublishers.ofString("{\"prompt\":\"Tell me a story about {about}\",\"inputs\":[{\"key\":\"about\",\"optional\":false,\"initial_value\":\"Leaning Tower of Pisa\"}],\"return_prompt\":\"Return the result in a markdown format\",\"prompt_guard\":[\"sexual_content\",\"defamation\"]}"))
.setHeader("Content-Type", "application/json")
.setHeader("x-api-key", "your-api-key")
.build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

import Foundation

let jsonData = [
"prompt": "Tell me a story about {about}",
"inputs": [
    [
        "key": "about",
        "optional": false,
        "initial_value": "Leaning Tower of Pisa"
    ]
],
"return_prompt": "Return the result in a markdown format",
"prompt_guard": [
    "sexual_content",
    "defamation"
]
] as [String : Any]
let data = try! JSONSerialization.data(withJSONObject: jsonData, options: [])

let url = URL(string: "https://api.jigsawstack.com/v1/prompt_engine")!
let headers = [
"Content-Type": "application/json",
"x-api-key": "your-api-key"
]

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = data as Data

let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if let error = error {
    print(error)
} else if let data = data {
    let str = String(data: data, encoding: .utf8)
    print(str ?? "")
}
}

task.resume()

import 'package:http/http.dart' as http;

void main() async {
final headers = {
'Content-Type': 'application/json',
'x-api-key': 'your-api-key',
};

final data = '{"prompt":"Tell me a story about {about}","inputs":[{"key":"about","optional":false,"initial_value":"Leaning Tower of Pisa"}],"return_prompt":"Return the result in a markdown format","prompt_guard":["sexual_content","defamation"]}';

final url = Uri.parse('https://api.jigsawstack.com/v1/prompt_engine');

final res = await http.post(url, headers: headers, body: data);
final status = res.statusCode;
if (status != 200) throw Exception('http.post error: statusCode= $status');

print(res.body);
}

import java.io.IOException
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody

val client = OkHttpClient()

val MEDIA_TYPE = "application/json".toMediaType()

val requestBody = "{\"prompt\":\"Tell me a story about {about}\",\"inputs\":[{\"key\":\"about\",\"optional\":false,\"initial_value\":\"Leaning Tower of Pisa\"}],\"return_prompt\":\"Return the result in a markdown format\",\"prompt_guard\":[\"sexual_content\",\"defamation\"]}"

val request = Request.Builder()
.url("https://api.jigsawstack.com/v1/prompt_engine")
.post(requestBody.toRequestBody(MEDIA_TYPE))
.header("Content-Type", "application/json")
.header("x-api-key", "your-api-key")
.build()

client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
response.body!!.string()
}

using System.Net.Http.Headers;
using System.Net.Http.Json;

HttpClient client = new HttpClient();

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://api.jigsawstack.com/v1/prompt_engine");
request.Headers.Add("x-api-key", "your-api-key");
request.Content = JsonContent.Create(new
{
prompt = "Tell me a story about {about}",
inputs = new List<object> { {"key":"about","optional":false,"initial_value":"Leaning Tower of Pisa"} },
return_prompt = "Return the result in a markdown format",
prompt_guard = new List<string> { "sexual_content", "defamation" }
});
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

HttpResponseMessage response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();

Console.WriteLine(responseBody);
{
  "success": true,
  "prompt_engine_id": "dea57da0-eea1-400f-b5df-2f6216a4c2b9",
  "optimized_prompt": "Write a detailed and engaging story about {about}, including vivid descriptions, well-developed characters, and a clear beginning, middle, and end.",
  "_usage": {
        "input_tokens": 58,
        "output_tokens": 61,
        "inference_time_tokens": 1121,
        "total_tokens": 1240
  }
}