Crea un template da un prompt
Crea un template da un prompt identificando ed estraendo le variabili
Le API degli strumenti per i prompt sono in una closed research preview. Richiedi di partecipare alla closed research preview.
Prima di iniziare
Gli strumenti per i prompt sono un insieme di API per generare e migliorare i prompt. A differenza delle nostre altre API, questa è un’API sperimentale: dovrai richiedere l’accesso e non ha lo stesso livello di impegno per il supporto a lungo termine come le altre API.
Queste API sono simili a quelle disponibili in Anthropic Workbench e sono destinate all’uso da parte di altre piattaforme e ambienti di prompt engineering.
Iniziare con il miglioratore di prompt
Per utilizzare l’API di generazione dei prompt, dovrai:
- Essere stato ammesso alla closed research preview per le API degli strumenti per i prompt
- Utilizzare l’API direttamente, invece che l’SDK
- Aggiungere l’header beta
prompt-tools-2025-04-02
Questa API non è disponibile nell’SDK
Crea un template da un prompt
Headers
Optional header to specify the beta version(s) you want to use.
To use multiple betas, use a comma separated list like beta1,beta2
or specify the header multiple times for each beta.
Body
The prompt to templatize, structured as a list of message
objects.
Each message in the messages
array must:
- Contain only text-only content blocks
- Not include tool calls, images, or prompt caching blocks
Example of a simple text prompt:
[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Translate hello to German"
}
]
}
]
Note that only contiguous user messages with text content are allowed. Assistant prefill is permitted, but other content types will cause validation errors.
[
{
"content": [
{
"text": "Translate hello to German",
"type": "text"
}
],
"role": "user"
}
]
The existing system prompt to templatize.
{
"system": "You are a professional English to German translator",
[...]
}
Note that this differs from the Messages API; it is strictly a string.
"You are a professional English to German translator"
Response
The templatized prompt with variable placeholders.
The response includes the input messages with specific values replaced by variable placeholders. These messages maintain the original message structure but contain uppercase variable names in place of concrete values.
For example, an input message content like "Translate hello to German"
would be transformed to "Translate {{WORD_TO_TRANSLATE}} to {{TARGET_LANGUAGE}}"
.
{
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Translate {{WORD_TO_TRANSLATE}} to {{TARGET_LANGUAGE}}"
}
]
}
]
}
[
{
"content": [
{
"text": "Translate {{WORD_TO_TRANSLATE}} to {{TARGET_LANGUAGE}}",
"type": "text"
}
],
"role": "user"
}
]
The input system prompt with variables identified and replaced.
If no system prompt was provided in the original request, this field will be an empty string.
"You are a professional English to {{TARGET_LANGUAGE}} translator"
Usage information
A mapping of template variable names to their original values, as extracted from the input prompt during templatization. Each key represents a variable name identified in the templatized prompt, and each value contains the corresponding content from the original prompt that was replaced by that variable.
Example:
"variable_values": {
"WORD_TO_TRANSLATE": "hello",
"TARGET_LANGUAGE": "German"
}
In this example response, the original prompt – Translate hello to German
– was templatized to Translate WORD_TO_TRANSLATE to TARGET_LANGUAGE
, with the variable values extracted as shown.
{
"TARGET_LANGUAGE": "German",
"WORD_TO_TRANSLATE": "hello"
}