Prompt Completion
Create Prompt Completion
POST /prompts/:id/completions
Creates a completion for the given prompt ID created in Portkey through the Prompts tab.
Creates a completion for the selected prompt ID
POST
https://api.portkey.ai/v1/prompts/:id/completions
Path Parameters
Name | Type | Description |
---|---|---|
id* | String | The prompt ID to use for the completion request. |
Request Body
Name | Type | Description |
---|---|---|
variables* | Object | The variables mentioned in the prompt template being used |
hyperparameters | Multiple | Add any hyperparameters to the request to override the ones set in the prompt definition |
stream | boolean | Incrementally stream the response using server-sent events. Defaults to false |
The API expects the prompt ID, prompt variables and optionally any hyperparameters to override for this request. It returns the chat completion or completion object in the unified format which is OpenAI signature compliant.
SDK Usage
The prompts.completions.create
method in the Portkey SDK provides a way to generate a prompt completion.
Method Signature
prompt.completions.create(promptParams)
Parameters
- promptParams (Object): Parameters for the prompt completion request including promptID, variables and optionally any hyperparameters for the completion.
Example Usage
import Portkey from 'portkey-ai'
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY",
})
// Make the prompt creation call with the variables
const promptCompletion = await portkey.prompts.completions.create({
promptID: "Your Prompt ID",
variables: {
// The variables specified in the prompt
}
})
// We can also override the hyperparameters
const promptCompletion = await portkey.prompts.completions.create({
promptID: "Your Prompt ID",
variables: {
// The variables specified in the prompt
},
max_tokens: 250,
presence_penalty: 0.2
})
Streaming Mode
With the new **/prompts/:id/completions**
route, it is mandatory to set **stream:True**
while making the call—if you want to stream the responses.This is a departure from when you could toggle the stream mode in Portkey prompt playground UI, and have the request automatically return streamed response. Now, regardless of the stream toggle state in the prompt playground, if you want streaming mode, you must set it to true at the time of making the call.
prompt.completions.create(promptParams)
Parameters
- promptParams (Object): Parameters for the prompt completion request including promptID, variables and optionally any hyperparameters for the completion.
Example Usage
const streamPromptCompletion = await portkey.prompts.completions.create({
promptID: "Your Prompt ID",
variables: {
// The variables specified in the prompt
},
stream: true // Defaults to false
})