Reusable Prompts with variables #398
Answered
by
StephenHodgson
ArnaudC2Care
asked this question in
Q&A
-
Hello, I’m having trouble figuring out whether it’s possible to use Reusable Prompts with the responsesAPI, and if so, how to properly do it. I'm referring to the example from the OpenAI documentation: const response = await client.responses.create({
model: "gpt-4.1",
prompt: {
id: "pmpt_abc123",
version: "2",
variables: {
customer_name: "Jane Doe",
product: "40oz juice box"
}
}
}); I’d like to use a reusable prompt in this way, injecting variables dynamically. Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
StephenHodgson
Jul 21, 2025
Replies: 1 comment 1 reply
-
First you'll need to create the prompt in the playground, then copy that id there. Then you'll pass it in the var conversation = new List<IResponseItem>
{
new Message(Role.User, "{{customer_name}} purchased {{product}}. What are some other recommendations we can give this customer?"),
};
var request = new CreateResponseRequest(
input: conversation,
model: Model.GPT4_1_Nano,
prompt: new Prompt("pmpt_abc123", new Dictionary<string, object>
{
{ "customer_name", "Jane Doe" },
{ "product", "40oz juice box" }
}));
var response = await OpenAIClient.ResponsesEndpoint.CreateModelResponseAsync(request); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ArnaudC2Care
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First you'll need to create the prompt in the playground, then copy that id there.
Then you'll pass it in the
CreateReponse
constructor: