AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Container for the parameters to the InvokeModel operation. Invokes the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body. You use model inference to generate text, images, and embeddings.

For example code, see Invoke model code examples in the Amazon Bedrock User Guide.

This operation requires permission for the bedrock:InvokeModel action.

To deny all inference access to resources that you specify in the modelId field, you need to deny access to the bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream actions. Doing this also denies access to the resource through the Converse API actions (Converse and ConverseStream). For more information see Deny access for inference on specific models.

For troubleshooting some of the common errors you might encounter when using the InvokeModel API, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide

Inheritance Hierarchy

System.Object
  Amazon.Runtime.AmazonWebServiceRequest
    Amazon.BedrockRuntime.AmazonBedrockRuntimeRequest
      Amazon.BedrockRuntime.Model.InvokeModelRequest

Namespace: Amazon.BedrockRuntime.Model
Assembly: AWSSDK.BedrockRuntime.dll
Version: 3.x.y.z

Syntax

C#
public class InvokeModelRequest : AmazonBedrockRuntimeRequest
         IAmazonWebServiceRequest

The InvokeModelRequest type exposes the following members

Constructors

NameDescription
Public Method InvokeModelRequest()

Properties

NameTypeDescription
Public Property Accept System.String

Gets and sets the property Accept.

The desired MIME type of the inference body in the response. The default value is application/json.

Public Property Body System.IO.MemoryStream

Gets and sets the property Body.

The prompt and inference parameters in the format specified in the contentType in the header. You must provide the body in JSON format. To see the format and content of the request and response bodies for different models, refer to Inference parameters. For more information, see Run inference in the Bedrock User Guide.

Public Property ContentType System.String

Gets and sets the property ContentType.

The MIME type of the input data in the request. You must specify application/json.

Public Property GuardrailIdentifier System.String

Gets and sets the property GuardrailIdentifier.

The unique identifier of the guardrail that you want to use. If you don't provide a value, no guardrail is applied to the invocation.

An error will be thrown in the following situations.

  • You don't provide a guardrail identifier but you specify the amazon-bedrock-guardrailConfig field in the request body.

  • You enable the guardrail but the contentType isn't application/json.

  • You provide a guardrail identifier, but guardrailVersion isn't specified.

Public Property GuardrailVersion System.String

Gets and sets the property GuardrailVersion.

The version number for the guardrail. The value can also be DRAFT.

Public Property ModelId System.String

Gets and sets the property ModelId.

The unique identifier of the model to invoke to run inference.

The modelId to provide depends on the type of model or throughput that you use:

Public Property PerformanceConfigLatency Amazon.BedrockRuntime.PerformanceConfigLatency

Gets and sets the property PerformanceConfigLatency.

Model performance settings for the request.

Public Property Trace Amazon.BedrockRuntime.Trace

Gets and sets the property Trace.

Specifies whether to enable or disable the Bedrock trace. If enabled, you can see the full Bedrock trace.

Version Information

.NET:
Supported in: 8.0 and newer, Core 3.1

.NET Standard:
Supported in: 2.0

.NET Framework:
Supported in: 4.5 and newer, 3.5