---
title: "POST /optimize-prompt"
method: POST
path: "/optimize-prompt"
---

# POST /optimize-prompt

`POST /optimize-prompt`

Optimizes a prompt for the task that you specify. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management-optimize.html">Optimize a prompt</a> in the <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html">Amazon Bedrock User Guide</a>.

## Request body

- object
  - `input` object, required — Contains information about the prompt to optimize.
    - `textPrompt` object — Contains information about the text prompt to optimize.
      - `text` string, required — The text in the text prompt to optimize.
  - `targetModelId` string, required — The unique identifier of the model that you want to optimize the prompt for.

## Response `200`

Success

- OptimizePromptResponse
  - `optimizedPrompt` object, required — The prompt after being optimized for the task.
    - `accessDeniedException` object — The request is denied because of missing access permissions. Check your permissions and retry your request.
      - `message` string
    - `analyzePromptEvent` object — An event in which the prompt was analyzed in preparation for optimization.
      - `message` string — A message describing the analysis of the prompt.
    - `badGatewayException` object — There was an issue with a dependency due to a server issue. Retry your request.
      - `message` string
      - `resourceName` string — The name of the dependency that caused the issue, such as Amazon Bedrock, Lambda, or STS.
    - `dependencyFailedException` object — There was an issue with a dependency. Check the resource configurations and retry the request.
      - `message` string
      - `resourceName` string — The name of the dependency that caused the issue, such as Amazon Bedrock, Lambda, or STS.
    - `internalServerException` object — An internal server error occurred. Retry your request.
      - `message` string
      - `reason` string — The reason for the exception. If the reason is <code>BEDROCK_MODEL_INVOCATION_SERVICE_UNAVAILABLE</code>, the model invocation service is unavailable. Retry your request.
    - `optimizedPromptEvent` object — An event in which the prompt was optimized.
      - `optimizedPrompt` object — Contains information about the optimized prompt.
        - `textPrompt` object — Contains information about the text in the prompt that was optimized.
          - `text` string, required — The text in the text prompt to optimize.
    - `throttlingException` object — Your request was throttled because of service-wide limitations. Resubmit your request later or in a different region. You can also purchase <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prov-throughput.html">Provisioned Throughput</a> to increase the rate or number of tokens you can process.
      - `message` string
    - `validationException` object — Input validation failed. Check your request parameters and retry the request.
      - `message` string

## Other responses

- `480` — ValidationException
- `481` — InternalServerException
- `482` — DependencyFailedException
- `483` — BadGatewayException
- `484` — ThrottlingException
- `485` — AccessDeniedException

---

[API](https://skmtc.net/aws/apis/bedrock-agent-runtime.md) · [All operations](https://skmtc.net/aws/apis/bedrock-agent-runtime/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/aws/bedrock-agent-runtime/versions/fe358131c0ad/schema)
