---
title: "generate"
sidebar_label: "generate"
description: "Kotlin binding reference: generate."
---

<!-- Generated by tools/api_reference/generate_api_docs.py. Do not edit. -->

//[clika-runtime](../../../index.md)/[io.clika.modelverse](../index.md)/[GenerativeModel](index.md)/[generate](generate.md)

# generate

[common]\
fun [generate](generate.md)(prompt: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)? = null, messages: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ChatMessage](../ChatMessage/index.md)&gt;? = null, config: [GenerationConfig](../GenerationConfig/index.md) = capabilities.defaults, images: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ByteArray](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html)&gt; = emptyList(), tools: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[ToolDef](../ToolDef/index.md)&gt; = emptyList(), toolChoice: [ToolChoice](../ToolChoice/index.md) = ToolChoice.Auto, stageObserver: [StageObserver](../StageObserver/index.md)? = null): [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)

One reply, blocking: [prompt](generate.md) as the user turn (with [images](generate.md)), or [messages](generate.md) as the conversation; exactly one of the two. A model with a chat template renders it, one without reads the prompt as text. Answers the reply's visible text; [report](report.md) then says how it ended and what it cost. [tools](generate.md) are offered under [toolChoice](generate.md), and the calls the reply made are on the report. [stageObserver](generate.md) hears this call's stages alone, beside the model's own ([setStageObserver](setStageObserver.md)). A failure throws [ModelverseException](../ModelverseException/index.md) with the library's message (an offer of tools to a model that takes none among them); a [close](close.md) while the reply runs ends it as [FinishReason.CANCELED](../FinishReason/CANCELED/index.md) with the text so far.