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
id*
String
The prompt ID to use for the completion request.
Request Body
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
const streamPromptCompletion = await portkey.prompts.completions.create({
promptID: "Your Prompt ID",
variables: {
// The variables specified in the prompt
},
stream: true // Defaults to false
})
Last updated
Was this helpful?