Skip to main content
/generate

Invoke a prompt and get the generated result.

Promptitude Team avatar
Written by Promptitude Team
Updated in the last hour

Endpoint

Simple send a POST request to the endpoint, including the Authorization Header and the Request Object.

Action

POST

Endpoint URL

Headers

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Body

The below Request Object (JSON)

Request Object

Here's an example of the request object for a prompt with two input variables:

{ 
"prompt": {
"promptId": "65a6sdf56f7asd6a7ssdasds",
"inputs": {
"variable1": "value1",
"variable2": "value2"
}
}
"endUserId": "raeyBqUgKtPXDDt0psFrREVjF902",
}

Attributes of the Request Object:


prompt object - required
​
Sets which prompt to generate and the values of the prompt's input variables.

promptId string - required
The ID of the prompt, as shown at the top of the prompt's detail page.

inputs hash
Set of key-value pairs of all the prompt's input variables.


endUserId string
​
Optional: A unique identifier of the final end-user who made the call.
Could be a hash of their UID or email address, so it's not identifiable.


Result Object

Here's an example of a result object after invoking a prompt:

{ 
"code": 200,
"message": "OK",
"error": false,
"results": {
"result": "Why did the developer need glasses? Because he couldn't C#!",
"logId": "Z2gV2otfCKIt17t76KFJ",
}
}

Attributes of the Result Object:


code number
Response code. 200 if everything went OK, otherwise the HTTP response code.


message string
"OK" if everything went well. If not, contains the detailed error message.


error boolean
Shows if an error occurred during the request.


Prompt that generate plain | formatted texts | lists

results object
Detailed results of the invocation of the prompt.

result string | array
Final generated output of the prompt, according to the Result Type.

logId string
Unique ID of this invocation. Use in /rate endpoint to add a star rating.


Prompt that generate data (JSON)

results object
Detailed results of the invocation of the prompt.

result JSON
Final generated output of the prompt, according to the Result Type.

logId string
Unique ID of this invocation. Use in /rate endpoint to add a star rating.

When you set the output format to JSON in Promptitude, the API response will include a new attribute called resultJSON. This attribute is designed to provide an organized and accessible structure of the AI provider's response.

Here is how the structure looks:
​

{ 
"results": {
"resultJSON": { ... }
...
}

The resultJSON object contains the response properties from the AI provider in a structured format, making it easy for you to access and work with the data.

However, if the AI provider returns an invalid JSON structure that cannot be correctly parsed into resultJSON, an error message will be included. This message is formatted like this:

{ 
"results": {
"resultJSON": {
"error": "The provider returned an invalid JSON response. Refer to the 'result' property for more details on the format error."
},
...
}

This approach allows you to quickly identify and diagnose any issues with the provider's response, ensuring that you can resolve errors efficiently and continue to leverage the power of your AI prompts effectively.

Did this answer your question?