CINXE.COM

InvokeModel - Amazon Bedrock

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>InvokeModel - Amazon Bedrock</title><meta name="viewport" content="width=device-width,initial-scale=1" /><meta name="assets_root" content="/assets" /><meta name="target_state" content="API_runtime_InvokeModel" /><meta name="default_state" content="API_runtime_InvokeModel" /><link rel="icon" type="image/ico" href="/assets/images/favicon.ico" /><link rel="shortcut icon" type="image/ico" href="/assets/images/favicon.ico" /><link rel="canonical" href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html" /><meta name="description" content="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." /><meta name="deployment_region" content="IAD" /><meta name="product" content="Amazon Bedrock" /><meta name="guide" content="API Reference" /><meta name="abstract" content="Details about operations and parameters in the Amazon Bedrock API Reference" /><meta name="guide-locale" content="en_us" /><meta name="tocs" content="toc-contents.json" /><link rel="canonical" href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html" /><link rel="alternative" href="https://docs.aws.amazon.com/id_id/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="id-id" /><link rel="alternative" href="https://docs.aws.amazon.com/id_id/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="id" /><link rel="alternative" href="https://docs.aws.amazon.com/de_de/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="de-de" /><link rel="alternative" href="https://docs.aws.amazon.com/de_de/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="de" /><link rel="alternative" href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="en-us" /><link rel="alternative" href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="en" /><link rel="alternative" href="https://docs.aws.amazon.com/es_es/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="es-es" /><link rel="alternative" href="https://docs.aws.amazon.com/es_es/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="es" /><link rel="alternative" href="https://docs.aws.amazon.com/fr_fr/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="fr-fr" /><link rel="alternative" href="https://docs.aws.amazon.com/fr_fr/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="fr" /><link rel="alternative" href="https://docs.aws.amazon.com/it_it/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="it-it" /><link rel="alternative" href="https://docs.aws.amazon.com/it_it/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="it" /><link rel="alternative" href="https://docs.aws.amazon.com/ja_jp/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="ja-jp" /><link rel="alternative" href="https://docs.aws.amazon.com/ja_jp/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="ja" /><link rel="alternative" href="https://docs.aws.amazon.com/ko_kr/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="ko-kr" /><link rel="alternative" href="https://docs.aws.amazon.com/ko_kr/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="ko" /><link rel="alternative" href="https://docs.aws.amazon.com/pt_br/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="pt-br" /><link rel="alternative" href="https://docs.aws.amazon.com/pt_br/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="pt" /><link rel="alternative" href="https://docs.aws.amazon.com/zh_cn/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="zh-cn" /><link rel="alternative" href="https://docs.aws.amazon.com/zh_tw/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="zh-tw" /><link rel="alternative" href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html" hreflang="x-default" /><meta name="feedback-item" content="Bedrock-AI" /><meta name="this_doc_product" content="Amazon Bedrock" /><meta name="this_doc_guide" content="API Reference" /><script defer="" src="/assets/r/vendor4.js?version=2021.12.02"></script><script defer="" src="/assets/r/vendor3.js?version=2021.12.02"></script><script defer="" src="/assets/r/vendor1.js?version=2021.12.02"></script><script defer="" src="/assets/r/awsdocs-common.js?version=2021.12.02"></script><script defer="" src="/assets/r/awsdocs-doc-page.js?version=2021.12.02"></script><link href="/assets/r/vendor4.css?version=2021.12.02" rel="stylesheet" /><link href="/assets/r/awsdocs-common.css?version=2021.12.02" rel="stylesheet" /><link href="/assets/r/awsdocs-doc-page.css?version=2021.12.02" rel="stylesheet" /><script async="" id="awsc-panorama-bundle" type="text/javascript" src="https://prod.pa.cdn.uis.awsstatic.com/panorama-nav-init.js" data-config="{'appEntity':'aws-documentation','region':'us-east-1','service':'bedrock'}"></script><meta id="panorama-serviceSubSection" value="API Reference" /><meta id="panorama-serviceConsolePage" value="InvokeModel" /></head><body class="awsdocs awsui"><div class="awsdocs-container"><awsdocs-header></awsdocs-header><awsui-app-layout id="app-layout" class="awsui-util-no-gutters" ng-controller="ContentController as $ctrl" header-selector="awsdocs-header" navigation-hide="false" navigation-width="$ctrl.navWidth" navigation-open="$ctrl.navOpen" navigation-change="$ctrl.onNavChange($event)" tools-hide="$ctrl.hideTools" tools-width="$ctrl.toolsWidth" tools-open="$ctrl.toolsOpen" tools-change="$ctrl.onToolsChange($event)"><div id="guide-toc" dom-region="navigation"><awsdocs-toc></awsdocs-toc></div><div id="main-column" dom-region="content" tabindex="-1"><awsdocs-view class="awsdocs-view"><div id="awsdocs-content"><head><title>InvokeModel - Amazon Bedrock</title><meta name="pdf" content="/pdfs/bedrock/latest/APIReference/bedrock-api.pdf#API_runtime_InvokeModel" /><meta name="forums" content="https://repost.aws/tags/TAQeKlaPaNRQ2tWB6P7KrMag" /><meta name="feedback" content="https://docs.aws.amazon.com/forms/aws-doc-feedback?hidden_service_name=Bedrock-AI&amp;topic_url=https://docs.aws.amazon.com/en_us/bedrock/latest/APIReference/API_runtime_InvokeModel.html" /><meta name="feedback-yes" content="feedbackyes.html?topic_url=https://docs.aws.amazon.com/en_us/bedrock/latest/APIReference/API_runtime_InvokeModel.html" /><meta name="feedback-no" content="feedbackno.html?topic_url=https://docs.aws.amazon.com/en_us/bedrock/latest/APIReference/API_runtime_InvokeModel.html" /><meta name="keywords" content="API reference,API,requests,InvokeModel" /><script type="application/ld+json"> { "@context" : "https://schema.org", "@type" : "BreadcrumbList", "itemListElement" : [ { "@type" : "ListItem", "position" : 1, "name" : "AWS", "item" : "https://aws.amazon.com" }, { "@type" : "ListItem", "position" : 2, "name" : "Amazon Bedrock", "item" : "https://docs.aws.amazon.com/bedrock/index.html" }, { "@type" : "ListItem", "position" : 3, "name" : "API Reference", "item" : "https://docs.aws.amazon.com/bedrock/latest/APIReference" }, { "@type" : "ListItem", "position" : 4, "name" : "Amazon Bedrock API Reference", "item" : "https://docs.aws.amazon.com/bedrock/latest/APIReference/welcome.html" }, { "@type" : "ListItem", "position" : 5, "name" : "Actions", "item" : "https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations.html" }, { "@type" : "ListItem", "position" : 6, "name" : "Amazon Bedrock Runtime", "item" : "https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Amazon_Bedrock_Runtime.html" }, { "@type" : "ListItem", "position" : 7, "name" : "InvokeModel", "item" : "https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Operations_Amazon_Bedrock_Runtime.html" } ] } </script></head><body><div id="main"><div style="display: none"><a href="/pdfs/bedrock/latest/APIReference/bedrock-api.pdf#API_runtime_InvokeModel" target="_blank" rel="noopener noreferrer" title="Open PDF"></a></div><div id="breadcrumbs" class="breadcrumb"><a href="https://aws.amazon.com">AWS</a><a href="/index.html">Documentation</a><a href="/bedrock/index.html">Amazon Bedrock</a><a href="welcome.html">API Reference</a></div><div id="page-toc-src"><a href="#API_runtime_InvokeModel_RequestSyntax">Request Syntax</a><a href="#API_runtime_InvokeModel_RequestParameters">URI Request Parameters</a><a href="#API_runtime_InvokeModel_RequestBody">Request Body</a><a href="#API_runtime_InvokeModel_ResponseSyntax">Response Syntax</a><a href="#API_runtime_InvokeModel_ResponseElements">Response Elements</a><a href="#API_runtime_InvokeModel_Errors">Errors</a><a href="#API_runtime_InvokeModel_Examples">Examples</a><a href="#API_runtime_InvokeModel_SeeAlso">See Also</a></div><div id="main-content" class="awsui-util-container"><div id="main-col-body"><awsdocs-language-banner data-service="$ctrl.pageService"></awsdocs-language-banner><h1 class="topictitle" id="API_runtime_InvokeModel">InvokeModel</h1><div class="awsdocs-page-header-container"><awsdocs-page-header></awsdocs-page-header><awsdocs-filter-selector id="awsdocs-filter-selector"></awsdocs-filter-selector></div><p>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.</p><p>For example code, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/inference-invoke.html#inference-example-invoke">Invoke model code examples</a>. </p><p>This operation requires permission for the <code class="code">bedrock:InvokeModel</code> action.</p><div class="awsdocs-note awsdocs-important"><div class="awsdocs-note-title"><awsui-icon name="status-warning" variant="error"></awsui-icon><h6>Important</h6></div><div class="awsdocs-note-text"><p>To deny all inference access to resources that you specify in the modelId field, you need to deny access to the <code class="code">bedrock:InvokeModel</code> and <code class="code">bedrock:InvokeModelWithResponseStream</code> actions. Doing this also denies access to the resource through the Converse API actions (<a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html">Converse</a> and <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html">ConverseStream</a>). For more information see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-deny-inference">Deny access for inference on specific models</a>. </p></div></div><p>For troubleshooting some of the common errors you might encounter when using the <code class="code">InvokeModel</code> API, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html">Troubleshooting Amazon Bedrock API Error Codes</a> in the Amazon Bedrock User Guide</p> <h2 id="API_runtime_InvokeModel_RequestSyntax">Request Syntax</h2> <pre class="programlisting"><div class="code-btn-container"></div><!--DEBUG: cli ()--><code class="nohighlight">POST /model/<code class="replaceable">modelId</code>/invoke HTTP/1.1 Accept: <code class="replaceable">accept</code> Content-Type: <code class="replaceable">contentType</code> X-Amzn-Bedrock-GuardrailIdentifier: <code class="replaceable">guardrailIdentifier</code> X-Amzn-Bedrock-GuardrailVersion: <code class="replaceable">guardrailVersion</code> X-Amzn-Bedrock-Trace: <code class="replaceable">trace</code> <code class="replaceable">body</code></code></pre> <h2 id="API_runtime_InvokeModel_RequestParameters">URI Request Parameters</h2> <p>The request uses the following URI parameters.</p> <div class="variablelist"> <dl> <dt id="bedrock-runtime_InvokeModel-request-accept"><span class="term"> <b> <a href="#API_runtime_InvokeModel_RequestSyntax">accept</a> </b> </span></dt> <dd> <p>The desired MIME type of the inference body in the response. The default value is <code class="code">application/json</code>.</p> </dd> <dt id="bedrock-runtime_InvokeModel-request-contentType"><span class="term"> <b> <a href="#API_runtime_InvokeModel_RequestSyntax">contentType</a> </b> </span></dt> <dd> <p>The MIME type of the input data in the request. You must specify <code class="code">application/json</code>.</p> </dd> <dt id="bedrock-runtime_InvokeModel-request-guardrailIdentifier"><span class="term"> <b> <a href="#API_runtime_InvokeModel_RequestSyntax">guardrailIdentifier</a> </b> </span></dt> <dd> <p>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.</p> <p>An error will be thrown in the following situations.</p> <div class="itemizedlist"> <ul class="itemizedlist"><li class="listitem"> <p>You don't provide a guardrail identifier but you specify the <code class="code">amazon-bedrock-guardrailConfig</code> field in the request body.</p> </li><li class="listitem"> <p>You enable the guardrail but the <code class="code">contentType</code> isn't <code class="code">application/json</code>.</p> </li><li class="listitem"> <p>You provide a guardrail identifier, but <code class="code">guardrailVersion</code> isn't specified.</p> </li></ul></div> <p>Length Constraints: Minimum length of 0. Maximum length of 2048.</p> <p>Pattern: <code class="code">^(([a-z0-9]+)|(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]<span>{</span>1,20}:[0-9]<span>{</span>12}:guardrail/[a-z0-9]+))$</code> </p> </dd> <dt id="bedrock-runtime_InvokeModel-request-guardrailVersion"><span class="term"> <b> <a href="#API_runtime_InvokeModel_RequestSyntax">guardrailVersion</a> </b> </span></dt> <dd> <p>The version number for the guardrail. The value can also be <code class="code">DRAFT</code>.</p> <p>Pattern: <code class="code">^(([1-9][0-9]<span>{</span>0,7})|(DRAFT))$</code> </p> </dd> <dt id="bedrock-runtime_InvokeModel-request-uri-modelId"><span class="term"> <b> <a href="#API_runtime_InvokeModel_RequestSyntax">modelId</a> </b> </span></dt> <dd> <p>The unique identifier of the model to invoke to run inference.</p> <p>The <code class="code">modelId</code> to provide depends on the type of model or throughput that you use:</p> <div class="itemizedlist"> <ul class="itemizedlist"><li class="listitem"> <p>If you use a base model, specify the model ID or its ARN. For a list of model IDs for base models, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html#model-ids-arns">Amazon Bedrock base model IDs (on-demand throughput)</a> in the Amazon Bedrock User Guide.</p> </li><li class="listitem"> <p>If you use an inference profile, specify the inference profile ID or its ARN. For a list of inference profile IDs, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference-support.html">Supported Regions and models for cross-region inference</a> in the Amazon Bedrock User Guide.</p> </li><li class="listitem"> <p>If you use a provisioned model, specify the ARN of the Provisioned Throughput. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prov-thru-use.html">Run inference using a Provisioned Throughput</a> in the Amazon Bedrock User Guide.</p> </li><li class="listitem"> <p>If you use a custom model, first purchase Provisioned Throughput for it. Then specify the ARN of the resulting provisioned model. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-use.html">Use a custom model in Amazon Bedrock</a> in the Amazon Bedrock User Guide.</p> </li><li class="listitem"> <p>If you use an <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-import-model.html">imported model</a>, specify the ARN of the imported model. You can get the model ARN from a successful call to <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelImportJob.html">CreateModelImportJob</a> or from the Imported models page in the Amazon Bedrock console.</p> </li></ul></div> <p>Length Constraints: Minimum length of 1. Maximum length of 2048.</p> <p>Pattern: <code class="code">^(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]<span>{</span>1,20}:(([0-9]<span>{</span>12}:custom-model/[a-z0-9-]<span>{</span>1,63}[.]<span>{</span>1}[a-z0-9-]<span>{</span>1,63}/[a-z0-9]<span>{</span>12})|(:foundation-model/[a-z0-9-]<span>{</span>1,63}[.]<span>{</span>1}[a-z0-9-]<span>{</span>1,63}([.:]?[a-z0-9-]<span>{</span>1,63}))|([0-9]<span>{</span>12}:imported-model/[a-z0-9]<span>{</span>12})|([0-9]<span>{</span>12}:provisioned-model/[a-z0-9]<span>{</span>12})|([0-9]<span>{</span>12}:(inference-profile|application-inference-profile)/[a-zA-Z0-9-:.]+)))|([a-z0-9-]<span>{</span>1,63}[.]<span>{</span>1}[a-z0-9-]<span>{</span>1,63}([.:]?[a-z0-9-]<span>{</span>1,63}))|(([0-9a-zA-Z][_-]?)+)|([a-zA-Z0-9-:.]+)$|(^(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]<span>{</span>1,20}:[0-9]<span>{</span>12}:prompt/[0-9a-zA-Z]<span>{</span>10}(?::[0-9]<span>{</span>1,5})?))$</code> </p> <p>Required: Yes</p> </dd> <dt id="bedrock-runtime_InvokeModel-request-trace"><span class="term"> <b> <a href="#API_runtime_InvokeModel_RequestSyntax">trace</a> </b> </span></dt> <dd> <p>Specifies whether to enable or disable the Bedrock trace. If enabled, you can see the full Bedrock trace.</p> <p>Valid Values: <code class="code">ENABLED | DISABLED</code> </p> </dd> </dl></div> <h2 id="API_runtime_InvokeModel_RequestBody">Request Body</h2> <p>The request accepts the following binary data.</p> <div class="variablelist"> <dl> <dt id="bedrock-runtime_InvokeModel-request-body"><span class="term"> <b> <a href="#API_runtime_InvokeModel_RequestSyntax">body</a> </b> </span></dt> <dd> <p>The prompt and inference parameters in the format specified in the <code class="code">contentType</code> 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 <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html">Run inference</a> in the Bedrock User Guide.</p> <p>Length Constraints: Minimum length of 0. Maximum length of 25000000.</p> </dd> </dl></div> <h2 id="API_runtime_InvokeModel_ResponseSyntax">Response Syntax</h2> <pre class="programlisting"><div class="code-btn-container"></div><!--DEBUG: cli ()--><code class="nohighlight">HTTP/1.1 200 Content-Type: <code class="replaceable">contentType</code> <code class="replaceable">body</code></code></pre> <h2 id="API_runtime_InvokeModel_ResponseElements">Response Elements</h2> <p>If the action is successful, the service sends back an HTTP 200 response.</p> <p>The response returns the following HTTP headers.</p> <div class="variablelist"> <dl> <dt id="bedrock-runtime_InvokeModel-response-contentType"><span class="term"> <b> <a href="#API_runtime_InvokeModel_ResponseSyntax">contentType</a> </b> </span></dt> <dd> <p>The MIME type of the inference result.</p> </dd> </dl></div> <p>The response returns the following as the HTTP body.</p> <div class="variablelist"> <dl> <dt id="bedrock-runtime_InvokeModel-response-body"><span class="term"> <b> <a href="#API_runtime_InvokeModel_ResponseSyntax">body</a> </b> </span></dt> <dd> <p>Inference response from the model in the format specified in the <code class="code">contentType</code> header. To see the format and content of the request and response bodies for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>.</p> <p>Length Constraints: Minimum length of 0. Maximum length of 25000000.</p> </dd> </dl></div> <h2 id="API_runtime_InvokeModel_Errors">Errors</h2> <p>For information about the errors that are common to all actions, see <a href="./CommonErrors.html">Common Errors</a>.</p> <div class="variablelist"> <dl> <dt><span class="term"> <b> AccessDeniedException </b> </span></dt> <dd> <p>The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-access-denied">AccessDeniedException</a> in the Amazon Bedrock User Guide</p> <p>HTTP Status Code: 403</p> </dd> <dt><span class="term"> <b> InternalServerException </b> </span></dt> <dd> <p>An internal server error occurred. For troubleshooting this error, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-internal-failure">InternalFailure</a> in the Amazon Bedrock User Guide</p> <p>HTTP Status Code: 500</p> </dd> <dt><span class="term"> <b> ModelErrorException </b> </span></dt> <dd> <p>The request failed due to an error while processing the model.</p> <p>HTTP Status Code: 424</p> </dd> <dt><span class="term"> <b> ModelNotReadyException </b> </span></dt> <dd> <p>The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see <a href="https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html">Retry behavior</a> in the <em>AWS SDKs and Tools</em> reference guide.</p> <p>HTTP Status Code: 429</p> </dd> <dt><span class="term"> <b> ModelTimeoutException </b> </span></dt> <dd> <p>The request took too long to process. Processing time exceeded the model timeout length.</p> <p>HTTP Status Code: 408</p> </dd> <dt><span class="term"> <b> ResourceNotFoundException </b> </span></dt> <dd> <p>The specified resource ARN was not found. For troubleshooting this error, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-resource-not-found">ResourceNotFound</a> in the Amazon Bedrock User Guide</p> <p>HTTP Status Code: 404</p> </dd> <dt><span class="term"> <b> ServiceQuotaExceededException </b> </span></dt> <dd> <p>Your request exceeds the service quota for your account. You can view your quotas at <a href="https://docs.aws.amazon.com/servicequotas/latest/userguide/gs-request-quota.html">Viewing service quotas</a>. You can resubmit your request later.</p> <p>HTTP Status Code: 400</p> </dd> <dt><span class="term"> <b> ServiceUnavailableException </b> </span></dt> <dd> <p>The service isn't currently available. For troubleshooting this error, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-service-unavailable">ServiceUnavailable</a> in the Amazon Bedrock User Guide</p> <p>HTTP Status Code: 503</p> </dd> <dt><span class="term"> <b> ThrottlingException </b> </span></dt> <dd> <p>Your request was denied due to exceeding the account quotas for <em>Amazon Bedrock</em>. For troubleshooting this error, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-throttling-exception">ThrottlingException</a> in the Amazon Bedrock User Guide</p> <p>HTTP Status Code: 429</p> </dd> <dt><span class="term"> <b> ValidationException </b> </span></dt> <dd> <p>The input fails to satisfy the constraints specified by <em>Amazon Bedrock</em>. For troubleshooting this error, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-validation-error">ValidationError</a> in the Amazon Bedrock User Guide</p> <p>HTTP Status Code: 400</p> </dd> </dl></div> <h2 id="API_runtime_InvokeModel_Examples">Examples</h2> <h3 id="API_runtime_InvokeModel_Example_1">Run inference on a text model</h3> <p>Send an invoke request to run inference on a Titan Text G1 - Express model. We set the <code class="code">accept</code> parameter to accept any content type in the response.</p> <h4 id="API_runtime_InvokeModel_Example_1_Request">Sample Request</h4> <pre class="programlisting"><div class="code-btn-container"></div><!--DEBUG: cli (http)--><code class="http ">POST https://bedrock-runtime.us-east-1.amazonaws.com/model/amazon.titan-text-express-v1/invoke -H accept: */* -H content-type: application/json Payload <span>{</span>"inputText": "Hello world"} </code></pre> <h3 id="API_runtime_InvokeModel_Example_2">Run inference on an image model</h3> <p>In the following example, the request sets the <code class="code">accept</code> parameter to <code class="code">image/png</code>.</p> <h4 id="API_runtime_InvokeModel_Example_2_Request">Sample Request</h4> <pre class="programlisting"><div class="code-btn-container"></div><!--DEBUG: cli (http)--><code class="http ">POST https://bedrock-runtime.us-east-1.amazonaws.com/model/stability.stable-diffusion-xl-v1/invoke -H accept: image/png -H content-type: application/json Payload <span>{</span>"inputText": "Picture of a bird"}</code></pre> <h3 id="API_runtime_InvokeModel_Example_3">Use a guardrail </h3> <p>This example shows how to use a guardrail with <code class="code">InvokeModel</code>.</p> <h4 id="API_runtime_InvokeModel_Example_3_Request">Sample Request</h4> <pre class="programlisting"><div class="code-btn-container"></div><!--DEBUG: cli (http)--><code class="http ">POST /model/modelId/invoke HTTP/1.1 Accept: accept Content-Type: contentType X-Amzn-Bedrock-GuardrailIdentifier: guardrailIdentifier X-Amzn-Bedrock-GuardrailVersion: guardrailVersion X-Amzn-Bedrock-GuardrailTrace: guardrailTrace X-Amzn-Bedrock-Trace: trace body // body <span>{</span> "amazon-bedrock-guardrailConfig": <span>{</span> "tagSuffix": "string" } }</code></pre> <h3 id="API_runtime_InvokeModel_Example_4">Example response</h3> <p>This is an example response from <code class="code">InvokeModel</code> when using a guardrail.</p> <h4 id="API_runtime_InvokeModel_Example_4_Request">Sample Request</h4> <pre class="programlisting"><div class="code-btn-container"></div><!--DEBUG: cli (http)--><code class="http ">HTTP/1.1 200 Content-Type: contentType body // body <span>{</span> "amazon-bedrock-guardrailAction": "INTERVENED | NONE", "amazon-bedrock-trace": <span>{</span> "guardrails": <span>{</span> // Detailed guardrail trace } } }</code></pre> <h3 id="API_runtime_InvokeModel_Example_5">Use an inference profile in model invocation</h3> <p>The following request calls the US Anthropic Claude 3.5 Sonnet inference profile to route traffic to the us-east-1 and us-west-2 regions.</p> <h4 id="API_runtime_InvokeModel_Example_5_Request">Sample Request</h4> <pre class="programlisting"><div class="code-btn-container"></div><!--DEBUG: cli (http)--><code class="http ">POST /model/us.anthropic.claude-3-5-sonnet-20240620-v1:0/invoke HTTP/1.1 <span>{</span> "anthropic_version": "bedrock-2023-05-31", "max_tokens": 1024, "messages": [ <span>{</span> "role": "user", "content": [ <span>{</span> "type": "text", "text": "Hello world" } ] } ] }</code></pre> <h2 id="API_runtime_InvokeModel_SeeAlso">See Also</h2> <p>For more information about using this API in one of the language-specific AWS SDKs, see the following:</p> <div class="itemizedlist"> <ul class="itemizedlist"><li class="listitem"> <p> <a href="https://docs.aws.amazon.com/goto/aws-cli/bedrock-runtime-2023-09-30/InvokeModel">AWS Command Line Interface</a> </p> </li><li class="listitem"> <p> <a href="https://docs.aws.amazon.com/goto/DotNetSDKV3/bedrock-runtime-2023-09-30/InvokeModel">AWS SDK for .NET</a> </p> </li><li class="listitem"> <p> <a href="https://docs.aws.amazon.com/goto/SdkForCpp/bedrock-runtime-2023-09-30/InvokeModel">AWS SDK for C++</a> </p> </li><li class="listitem"> <p> <a href="https://docs.aws.amazon.com/goto/SdkForGoV2/bedrock-runtime-2023-09-30/InvokeModel">AWS SDK for Go v2</a> </p> </li><li class="listitem"> <p> <a href="https://docs.aws.amazon.com/goto/SdkForJavaV2/bedrock-runtime-2023-09-30/InvokeModel">AWS SDK for Java V2</a> </p> </li><li class="listitem"> <p> <a href="https://docs.aws.amazon.com/goto/SdkForJavaScriptV3/bedrock-runtime-2023-09-30/InvokeModel">AWS SDK for JavaScript V3</a> </p> </li><li class="listitem"> <p> <a href="https://docs.aws.amazon.com/goto/SdkForPHPV3/bedrock-runtime-2023-09-30/InvokeModel">AWS SDK for PHP V3</a> </p> </li><li class="listitem"> <p> <a href="https://docs.aws.amazon.com/goto/boto3/bedrock-runtime-2023-09-30/InvokeModel">AWS SDK for Python</a> </p> </li><li class="listitem"> <p> <a href="https://docs.aws.amazon.com/goto/SdkForRubyV3/bedrock-runtime-2023-09-30/InvokeModel">AWS SDK for Ruby V3</a> </p> </li></ul></div> <awsdocs-copyright class="copyright-print"></awsdocs-copyright><awsdocs-thumb-feedback right-edge="{{$ctrl.thumbFeedbackRightEdge}}"></awsdocs-thumb-feedback></div><noscript><div><div><div><div id="js_error_message"><p><img src="https://d1ge0kk1l5kms0.cloudfront.net/images/G/01/webservices/console/warning.png" alt="Warning" /> <strong>Javascript is disabled or is unavailable in your browser.</strong></p><p>To use the Amazon Web Services Documentation, Javascript must be enabled. Please refer to your browser's Help pages for instructions.</p></div></div></div></div></noscript><div id="main-col-footer" class="awsui-util-font-size-0"><div id="doc-conventions"><a target="_top" href="/general/latest/gr/docconventions.html">Document Conventions</a></div><div class="prev-next"><div id="previous" class="prev-link" accesskey="p" href="./API_runtime_ConverseStream.html">ConverseStream</div><div id="next" class="next-link" accesskey="n" href="./API_runtime_InvokeModelWithResponseStream.html">InvokeModelWithResponseStream</div></div></div><awsdocs-page-utilities></awsdocs-page-utilities></div><div id="quick-feedback-yes" style="display: none;"><div class="title">Did this page help you? - Yes</div><div class="content"><p>Thanks for letting us know we're doing a good job!</p><p>If you've got a moment, please tell us what we did right so we can do more of it.</p><p><awsui-button id="fblink" rel="noopener noreferrer" target="_blank" text="Feedback" click="linkClick($event)" href="https://docs.aws.amazon.com/forms/aws-doc-feedback?hidden_service_name=Bedrock-AI&amp;topic_url=https://docs.aws.amazon.com/en_us/bedrock/latest/APIReference/API_runtime_InvokeModel.html"></awsui-button></p></div></div><div id="quick-feedback-no" style="display: none;"><div class="title">Did this page help you? - No</div><div class="content"><p>Thanks for letting us know this page needs work. We're sorry we let you down.</p><p>If you've got a moment, please tell us how we can make the documentation better.</p><p><awsui-button id="fblink" rel="noopener noreferrer" target="_blank" text="Feedback" click="linkClick($event)" href="https://docs.aws.amazon.com/forms/aws-doc-feedback?hidden_service_name=Bedrock-AI&amp;topic_url=https://docs.aws.amazon.com/en_us/bedrock/latest/APIReference/API_runtime_InvokeModel.html"></awsui-button></p></div></div></div></body></div></awsdocs-view><div class="page-loading-indicator" id="page-loading-indicator"><awsui-spinner size="large"></awsui-spinner></div></div><div id="tools-panel" dom-region="tools"><awsdocs-tools-panel id="awsdocs-tools-panel"></awsdocs-tools-panel></div></awsui-app-layout><awsdocs-cookie-banner class="doc-cookie-banner"></awsdocs-cookie-banner></div></body></html>

Pages: 1 2 3 4 5 6 7 8 9 10