> **Experimental**
>
> `@aws-cdk/aws-bedrock-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# ChatMessage

Represents a message in a chat conversation.

- Stability: [Experimental](/cdk/api/stability.html)
- Source: [`bedrock/prompts/chat-prompt-variant.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0-alpha.0/packages/@aws-cdk/aws-bedrock-alpha/bedrock/prompts/chat-prompt-variant.ts#L63)

## Example

```ts
const cmk = new kms.Key(this, 'cmk', {});

const variantChat = bedrock.PromptVariant.chat({
  variantName: 'variant1',
  model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
  messages: [
    bedrock.ChatMessage.user('From now on, you speak Japanese!'),
    bedrock.ChatMessage.assistant('Konnichiwa!'),
    bedrock.ChatMessage.user('From now on, you speak {{language}}!'),
  ],
  system: 'You are a helpful assistant that only speaks the language you`re told.',
  promptVariables: ['language'],
  toolConfiguration: {
    toolChoice: bedrock.ToolChoice.AUTO,
    tools: [
      bedrock.Tool.function({
        name: 'top_song',
        description: 'Get the most popular song played on a radio station.',
        inputSchema: {
          type: 'object',
          properties: {
            sign: {
              type: 'string',
              description: 'The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR.',
            },
          },
          required: ['sign'],
        },
      }),
    ],
  },
});

new bedrock.Prompt(this, 'prompt1', {
  promptName: 'prompt-chat',
  description: 'my first chat prompt',
  defaultVariant: variantChat,
  variants: [variantChat],
  kmsKey: cmk,
});
```

## Initializer

```ts
new ChatMessage(role: ChatMessageRole, text: string)
```

## Properties

- `role`: [ChatMessageRole](/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.ChatMessageRole.html) — The role of the message sender.

- `text`: string — The text content of the message.

## Methods

- `assistant(text: string): ChatMessage // chainable` (static) — Creates an assistant message.

  **Parameters**

  - `text` — - The text content of the assistant message.

  **Returns:** A ChatMessage instance representing an assistant message

- `user(text: string): ChatMessage // chainable` (static) — Creates a user message.

  **Parameters**

  - `text` — - The text content of the user message.

  **Returns:** A ChatMessage instance representing a user message
