# `LangChain.ChatModels.ChatVertexAI`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L1)

Parses and validates inputs for making a request for the Google AI  Chat API.

Converts response into more specialized `LangChain` data structures.

Example Usage:

```elixir
alias LangChain.Chains.LLMChain
alias LangChain.Message
alias LangChain.Message.ContentPart
alias LangChain.ChatModels.ChatVertexAI

config = %{
      model: "gemini-2.0-flash",
      api_key: ..., # vertex requires gcloud auth token https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal#rest
      temperature: 1.0,
      top_p: 0.8,
      receive_timeout: ...
    }
 model = ChatVertexAI.new!(config)

    %{llm: model, verbose: false, stream: false}
    |> LLMChain.new!()
    |> LLMChain.add_message(
      Message.new_user!([
        ContentPart.new!(%{type: :text, content: "Analyse the provided file and share a summary"}),
        ContentPart.new!(%{
          type: :file_url,
          content: ...,
          options: [media: ...]
        })
      ])
    )
    |> LLMChain.run()
The above call will return summary of the media content.
```

**Tool Schemas**

Vertex AI uses the same Gemini `Schema` type as
`LangChain.ChatModels.ChatGoogleAI`, which accepts a select subset of an
OpenAPI 3.0 schema object rather than full JSON Schema. Tool parameters and
the JSON response schema are passed through
`LangChain.Utils.GoogleSchema.sanitize/1` before being sent, which removes
the keywords the API has no field for. Note that dropping
`additionalProperties` means Vertex does not enforce closed objects, so
validate a tool call's arguments inside the tool's own function where that
matters.

**Structured Output**

Google's Gemini models can return
[structured JSON output](https://ai.google.dev/gemini-api/docs/structured-output)
that conforms to a schema you supply. Set `json_response: true` to request a
JSON response, and optionally provide a `json_schema` describing the shape you
want. These map to the API's `generationConfig.response_mime_type` and
`generationConfig.response_schema`.

```elixir
alias LangChain.Chains.LLMChain
alias LangChain.Message
alias LangChain.Message.ContentPart
alias LangChain.ChatModels.ChatVertexAI

# A response_schema in the Google/OpenAPI schema format.
json_schema = %{
  "type" => "array",
  "items" => %{
    "type" => "object",
    "properties" => %{
      "recipe_name" => %{"type" => "string"}
    }
  }
}

model =
  ChatVertexAI.new!(%{
    model: "gemini-2.5-flash",
    endpoint: ...,
    api_key: ...,
    json_response: true,
    json_schema: json_schema
  })

{:ok, updated_chain} =
  %{llm: model, verbose: false, stream: false}
  |> LLMChain.new!()
  |> LLMChain.add_message(Message.new_user!("List 5 popular cookie recipes"))
  |> LLMChain.run()

{:ok, recipes} =
  updated_chain.last_message.content
  |> ContentPart.content_to_string()
  |> Jason.decode()
```

The assistant message's content is a list of `LangChain.Message.ContentPart`
structs rather than a string, so flatten it with
`LangChain.Message.ContentPart.content_to_string/1` before decoding the JSON.

`json_response: true` may be used on its own (without a `json_schema`) to ask
for a JSON response without constraining its shape.

A `json_schema` is sanitized before it is sent, in the same way tool
parameters are, so keywords Google's `Schema` type has no field for are
dropped rather than rejected. Schemas generated by tooling commonly use
`$defs` and `$ref`; inline them first. See **Tool Schemas** above and
`LangChain.Utils.GoogleSchema` for the full list.

# `t`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L202)

```elixir
@type t() :: %LangChain.ChatModels.ChatVertexAI{
  api_key: term(),
  callbacks: term(),
  endpoint: term(),
  json_response: term(),
  json_schema: term(),
  model: term(),
  receive_timeout: term(),
  req_config: term(),
  safety_settings: term(),
  stream: term(),
  temperature: term(),
  thinking_config: term(),
  top_k: term(),
  top_p: term(),
  verbose_api: term()
}
```

# `call`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L586)

Calls the Google AI API passing the ChatVertexAI struct with configuration,
plus either a simple message or the list of messages to act as the prompt.

Optionally pass in a list of tools available to the LLM for requesting
execution in response.

**NOTE:** This function *can* be used directly, but the primary interface
should be through `LangChain.Chains.LLMChain`. The `ChatVertexAI` module is
more focused on translating the `LangChain` data structures to and from the
OpenAI API.

Another benefit of using `LangChain.Chains.LLMChain` is that it combines the
storage of messages, adding tools, adding custom context that should be passed
to tools, and automatically applying `LangChain.MessageDelta` structs as they
are are received, then converting those to the full `LangChain.Message` once
fully complete.

# `complete_final_delta`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L748)

# `do_process_response`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L752)

# `for_api`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L261)

# `get_message_contents`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L978)

```elixir
@spec get_message_contents(LangChain.MessageDelta.t() | LangChain.Message.t()) ::
  [%{required(String.t()) =&gt; any()}] | nil
```

Return the content parts for the message.

# `new`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L235)

```elixir
@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
```

Setup a ChatVertexAI client configuration.

# `new!`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L246)

```elixir
@spec new!(attrs :: map()) :: t() | no_return()
```

Setup a ChatVertexAI client configuration and return it or raise an error if invalid.

# `restore_from_map`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L1064)

Restores the model from the config.

# `retry_on_fallback?`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L1029)

```elixir
@spec retry_on_fallback?(LangChain.LangChainError.t()) :: boolean()
```

Determine if an error should be retried. If `true`, a fallback LLM may be
used. If `false`, the error is understood to be more fundamental with the
request rather than a service issue and it should not be retried or fallback
to another service.

# `serialize_config`
[🔗](https://github.com/brainlid/langchain/blob/v0.13.0/lib/chat_models/chat_vertex_ai.ex#L1040)

```elixir
@spec serialize_config(t()) :: %{required(String.t()) =&gt; any()}
```

Generate a config map that can later restore the model's configuration.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
