POST
/
v1
/
experimental
/
generate_prompt

提示詞工具 API 目前處於封閉研究預覽階段。申請加入封閉研究預覽

開始之前

提示詞工具是一組用於生成和改進提示詞的 API。與我們的其他 API 不同,這是一個實驗性 API:您需要申請訪問權限,且它不像其他 API 那樣具有相同程度的長期支援承諾。

這些 API 與 Anthropic Workbench 中提供的功能類似,旨在供其他提示詞工程平台和實驗環境使用。

開始使用提示詞生成器

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

  1. 已加入提示詞工具 API 的封閉研究預覽
  2. 直接使用 API,而不是 SDK
  3. 添加測試版標頭 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
task
string
required

Description of the prompt's purpose.

The task parameter tells Claude what the prompt should do or what kind of role or functionality you want to create. This helps guide the prompt generation process toward your intended use case.

Example:

{"task": "a chef for a meal prep planning service"}
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

The response contains a list of message objects in the same format used by the Messages API. Typically includes a user message with the complete generated prompt text, and may include an assistant message with a prefill to guide the model's initial response.

These messages can be used directly in a Messages API request to start a conversation with the generated prompt.

Example:

{
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "You are a chef for a meal prep planning service..."
        }
      ]
    },
    {
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": "<recipe_planning>"
        }
      ]
    }
  ]
}
system
string
default:
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 generating a prompt.

usage
object
required

Usage information