Mistral AI 模型

Gemini Enterprise Agent Platform 上的 Mistral AI 模型,提供全代管無伺服器模型做為 API。如要在 Agent Platform 使用 Mistral AI 模型,請直接傳送要求至 Agent Platform API 端點。Mistral AI 模型使用代管 API,因此不必佈建或管理基礎架構。

您可以串流回覆,縮短使用者感受到的延遲時間。串流回覆會使用伺服器傳送事件 (SSE),逐步串流回覆。

Mistral AI 模型採即付即用模式,如要瞭解 Mistral AI 模型的即付即用定價,請參閱 Gemini Enterprise Agent Platform 定價頁面。

可用的 Mistral AI 模型

Gemini Enterprise Agent Platform 提供下列 Mistral AI 模型。如要存取 Mistral AI 模型,請前往其 Model Garden 模型資訊卡。

Mistral Medium 3 多功能多模態模型,專為進階推論、程式設計、長脈絡文件理解、單一節點高處理量和 Agentic Workflows 設計。
Mistral OCR (25.05) 光學字元辨識 API,可深入理解文件,並擷取圖文交錯圖像、表格、圖表和 LaTeX 格式,用於多模態 RAG 管道。
Mistral Small 3.1 (25.03) 多用途、低延遲的多模態模型,脈絡窗口為 128,000 個詞元,專為高效率對話、程式設計和指令遵循而最佳化。
Codestral 2 專門用於程式碼生成的模型,可高精確度地填補中間內容 (FIM)、程式碼審查、重構程式碼,以及開發人員工具。

使用 Mistral AI 模型

您可以使用 curl 指令,透過下列模型名稱,將要求傳送至 Gemini Enterprise Agent Platform 端點:

  • 如果是 Mistral Medium 3,請使用 mistral-medium-3
  • 如要使用 Mistral OCR (25.05),請使用 mistral-ocr-2505
  • 如要使用 Mistral Small 3.1 (25.03),請使用 mistral-small-2503
  • 如果是 Codestral 2,請使用 codestral-2

如要進一步瞭解如何使用 Mistral AI SDK,請參閱 Mistral AI Gemini Enterprise Agent Platform 說明文件。

事前準備

如要透過 Gemini Enterprise Agent Platform 使用 Mistral AI 模型,請務必完成下列步驟。必須啟用 Agent Platform API (aiplatform.googleapis.com),才能使用 Gemini Enterprise Agent Platform。如果已有專案啟用 Agent Platform API,則可使用該專案,不必建立新專案。

  1. 登入 Google Cloud 帳戶。如果您未曾使用過 Google Cloud,歡迎建立帳戶,親自體驗實際使用我們產品的成效。新客戶還能獲得價值 $300 美元的免費抵免額,用於執行、測試及部署工作負載。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  8. 前往下列其中一個 Model Garden 模型資訊卡,然後按一下「Enable」(啟用):

對 Mistral AI 模型發出串流呼叫

下列範例會對 Mistral AI 模型發出串流呼叫。

REST

設定環境後,您可以使用 REST 測試文字提示詞。下列範例會將要求傳送至發布者模型端點。

使用任何要求資料之前,請先修改下列項目的值:

  • LOCATION:支援 Mistral AI 模型的區域。
  • MODEL:要使用的模型名稱。在要求主體中,排除 @ 模型版本號碼。
  • ROLE:與訊息相關聯的角色。您可以指定 user 或 assistant。第一則訊息必須使用 user 角色。模型會交替執行 user 和 assistant 回合。如果最後一則訊息使用 assistant 角色,回覆內容會緊接在該訊息的內容之後。您可以使用這項功能,限制模型的部分回覆。
  • STREAM:布林值,指定是否要串流回覆。串流回覆,減少使用者感受到的延遲。設為 true 即可串流回覆,設為 false 則會一次傳回所有回覆。
  • CONTENT:user 或 assistant 訊息的內容,例如文字。
  • MAX_OUTPUT_TOKENS:回覆內可以生成的詞元數量上限。一個詞元約為 3.5 個字元。100 個符記約等於 60 到 80 個字。

    如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:streamRawPredict

JSON 要求內文:

{
"model": MODEL,
  "messages": [
   {
    "role": "ROLE",
    "content": "CONTENT"
   }],
  "max_tokens": MAX_TOKENS,
  "stream": true
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:streamRawPredict"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:streamRawPredict" | Select-Object -Expand Content

您應該會收到如下的 JSON 回覆。

對 Mistral AI 模型發出單一呼叫

下列範例會對 Mistral AI 模型發出一元呼叫。

REST

設定環境後,您可以使用 REST 測試文字提示詞。下列範例會將要求傳送至發布者模型端點。

使用任何要求資料之前,請先修改下列項目的值:

  • LOCATION:支援 Mistral AI 模型的區域。
  • MODEL:要使用的模型名稱。在要求主體中,排除 @ 模型版本號碼。
  • ROLE:與訊息相關聯的角色。您可以指定 user 或 assistant。第一則訊息必須使用 user 角色。模型會交替執行 user 和 assistant 回合。如果最後一則訊息使用 assistant 角色,回覆內容會緊接在該訊息的內容之後。您可以使用這項功能,限制模型的部分回覆。
  • STREAM:布林值,指定是否要串流回覆。串流回覆,減少使用者感受到的延遲。設為 true 即可串流回覆,設為 false 則會一次傳回所有回覆。
  • CONTENT:user 或 assistant 訊息的內容,例如文字。
  • MAX_OUTPUT_TOKENS:回覆內可以生成的詞元數量上限。一個詞元約為 3.5 個字元。100 個符記約等於 60 到 80 個字。

    如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:rawPredict

JSON 要求內文:

{
"model": MODEL,
  "messages": [
   {
    "role": "ROLE",
    "content": "CONTENT"
   }],
  "max_tokens": MAX_TOKENS,
  "stream": false
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:rawPredict"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:rawPredict" | Select-Object -Expand Content

您應該會收到如下的 JSON 回覆。

Mistral AI 模型區域可用性和配額

Mistral AI 模型則是在每個可用區域都有配額。配額是以每分鐘查詢次數 (QPM) 和每分鐘詞元數 (TPM) 指定。TPM 包含輸入和輸出詞元。

模型 區域 配額 脈絡長度
Mistral Medium 3
us-central1
  • QPM:90
  • TPM:315,000
128,000
europe-west4
  • QPM:90
  • TPM:315,000
128,000
Mistral OCR (25.05)
us-central1
  • QPM:30
  • 每項要求頁數:30 (1 頁 = 100 萬個輸入詞元和 100 萬個輸出詞元)
30 頁
europe-west4
  • QPM:30
  • 每項要求頁數:30 (1 頁 = 100 萬個輸入詞元和 100 萬個輸出詞元)
30 頁
Mistral Small 3.1 (25.03)
us-central1
  • QPM:60
  • TPM:200,000
128,000
europe-west4
  • QPM:60
  • TPM:200,000
128,000
Codestral 2
us-central1
  • QPM:1,100
  • 輸入 TPM:1,100,000
  • 輸出 TPM:110,000
128,000 個詞元
europe-west4
  • QPM:1,100
  • 輸入 TPM:1,100,000
  • 輸出 TPM:110,000
128,000 個詞元

如要提高 Agent Platform 的配額,請使用 Google Cloud 控制台提出要求。如要進一步瞭解配額,請參閱「Cloud Quotas 總覽」。