POST
/
v1
/
experimental
/
improve_prompt

提示词工具API目前处于封闭研究预览阶段。申请加入封闭研究预览

开始之前

提示词工具是一组用于生成和改进提示词的API。与我们的其他API不同,这是一个实验性API:您需要申请访问权限,并且它不像其他API那样对长期支持做出相同程度的承诺。

这些API与Anthropic Workbench中提供的功能类似,旨在供其他提示词工程平台和实验环境使用。

开始使用提示词改进器

要使用提示词生成API,您需要:

  1. 已加入提示词工具API的封闭研究预览
  2. 直接使用API,而不是SDK
  3. 添加beta标头 prompt-tools-2025-04-02

此API在SDK中不可用

改进提示词

Headers

anthropic-beta
string[]

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.

x-api-key
string
required

Your unique API key for authentication.

This key is required in the header of all API requests, to authenticate your account and access Anthropic's services. Get your API key through the Console. Each key is scoped to a Workspace.

Body

application/json
messages
object[]
required

The prompt to improve, 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

As a simple text prompt:

[
  {
    "role": "user", 
    "content": [
      {
        "type": "text",
        "text": "Concise recipe for {{food}}"
      }
    ]
  }
]

With example interactions to guide improvement:

[
  {
    "role": "user", 
    "content": [
      {
        "type": "text",
        "text": "Concise for {{food}}.\n\nexample\mandu: Put the mandu in the air fryer at 380F for 7 minutes."
      }
    ]
  }
]

Note that only contiguous user messages with text content are allowed. Assistant prefill is permitted, but other content types will cause validation errors.

feedback
string | null

Feedback for improving the prompt.

Use this parameter to share specific guidance on what aspects of the prompt should be enhanced or modified.

Example:

{
  "messages": [...],
  "feedback": "Make the recipes shorter"
}

When not set, the API will improve the prompt using general prompt engineering best practices.

system
string | null

The existing system prompt to incorporate, if any.

{
  "system": "You are a professional meal prep chef",
  [...]
}

Note that while system prompts typically appear as separate parameters in standard API calls, in the improve_prompt response, the system content will be incorporated directly into the returned user message.

target_model
string | null
default:

The model this prompt will be used for. This optional parameter helps us understand which models our prompt tools are being used with, but it doesn't currently affect functionality.

Example:

"claude-3-7-sonnet-20250219"
Required string length: 1 - 256

Response

200 - application/json
messages
object[]
required

Contains the result of the prompt improvement process in a list of message objects.

Includes a user-role message with the improved prompt text and may optionally include an assistant-role message with a prefill. These messages follow the standard Messages API format and can be used directly in subsequent API calls.

system
string
required

Currently, the system field is always returned as an empty string (""). In future iterations, this field may contain generated system prompts.

Directions similar to what would normally be included in a system prompt are included in messages when improving a prompt.

usage
object
required

Usage information