Skip to content

[ERROR]: ValidationException: Cache configuration conflict

0

I am using BedRock's Invoke Model API, and am trying to use prompt caching. However, I get the following error:

ValidationException: Cache configuration conflict: Cannot enable prompt caching in message body when it is explicitly disabled in request header
    at de_ValidationExceptionRes (**<omitted>**/node_modules/@aws-sdk/client-bedrock-runtime/dist-cjs/index.js:1582:21)
    at de_CommandError (/Users/raquib/Documents/InsideDesk/parsely/node_modules/@aws-sdk/client-bedrock-runtime/dist-cjs/index.js:1399:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async **<omitted>**/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20
    at async **<omitted>**/node_modules/@smithy/core/dist-cjs/index.js:168:18
    at async **<omitted>**/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38
    at async **<omitted>**/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:34:22 {
  '$fault': 'client',
  '$metadata': {
    httpStatusCode: 400,
    requestId:<id>,
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  }
}

This is my request header:

{
  modelId: 'us.anthropic.claude-3-5-sonnet-20241022-v2:0',
  contentType: 'application/json',
  accept: 'application/json',
  inferenceProfileArn: **<omitted>**,
  explicitPromptCaching: 'enabled'
}

Even though explicitPromptCaching is enabled, I still get this error. Any reasons why? I am using version 3.714.0 of the package on npm

asked 2 years ago869 views

1 Answer
0

The error you're encountering suggests there's a conflict between the prompt caching configuration in your request header and the message body. Even though you've set explicitPromptCaching: 'enabled' in your request header, it seems that the message body of your request might be contradicting this setting.

To resolve this issue, you should check the following:

  1. Ensure that your request body (which is not shown in your provided code snippet) doesn't have any conflicting cache control settings. Look for any cache_control properties in your message body that might be set to disable caching.

  2. Make sure you're structuring your request body correctly. For the Claude 3.5 Sonnet v2 model, your body should include elements like anthropic_version, system, messages, and other parameters. Within the messages array, you can set cache control for specific parts of your prompt.

  3. If you're setting cache checkpoints in your request body, ensure they meet the minimum token requirement for the Claude 3.5 Sonnet v2 model.

  4. Double-check that you're not accidentally disabling caching in any part of your request, either in the header or the body.

  5. Verify that you're using the correct API call. For the InvokeModel API, prompt caching is enabled by default, so you might not need to explicitly enable it unless you're trying to modify its behavior.

If the issue persists after checking these points, you might want to try removing the explicitPromptCaching parameter from your request header altogether, as prompt caching is enabled by default for the InvokeModel API.

Remember, when using prompt caching, you need to structure your request carefully to ensure that the caching behavior aligns across both the header and the body of your request.
Sources
Prompt caching for faster model inference - Amazon Bedrock
Reduce costs and latency with Amazon Bedrock Intelligent Prompt Routing and prompt caching (preview) | AWS News Blog
Prompt Caching - Amazon Bedrock

answered 2 years ago

  • I removed explicitPromptCaching from my request header, but I get the same issue. My request body contains:

    { role: 'user' content: [{type: 'text', text: <pdf content>, cache_control: {type: 'ephemeral'}}, {type: 'text', text: 'what is this pdf about'}] }

    Also to note, the request works without prompt caching

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.