How to use glm model #1773
Replies: 2 comments
-
|
GLM models (from Zhipu AI) are not built into Koog directly, but you can connect to them easily through the OpenRouter integration, which Koog already supports out of the box. OpenRouter acts as a unified API gateway and carries all major GLM variants (e.g. Steps1. Add the OpenRouter client dependency to your implementation("ai.koog:prompt-executor-openrouter-client:<version>")2. Get an OpenRouter API key at openrouter.ai (free tier available). You do not need a separate Zhipu AI account — OpenRouter handles routing to Zhipu on your behalf. 3. Define the model and create an executor: import ai.koog.prompt.executor.clients.openrouter.OpenRouterLLMClient
import ai.koog.prompt.llm.LLMCapability
import ai.koog.prompt.llm.LLMProvider
import ai.koog.prompt.llm.LLModel
// Define GLM-4 Flash using its OpenRouter model ID
val glm4Flash = LLModel(
provider = LLMProvider.OpenRouter,
id = "zhipuai/glm-4-flash", // free-tier, fast
capabilities = listOf(
LLMCapability.Temperature,
LLMCapability.Tools,
LLMCapability.Completion,
)
)
val client = OpenRouterLLMClient(apiKey = System.getenv("OPEN_ROUTER_API_KEY"))4. Use it in an agent: val agent = AIAgent(
promptExecutor = simpleAIExecutor(client),
llmModel = glm4Flash,
systemPrompt = "You are a helpful assistant.",
toolRegistry = ToolRegistry.EMPTY,
)
val response = agent.run("Hello from Koog + GLM!")
println(response)Available GLM model IDs on OpenRouter
Browse all Zhipu models at openrouter.ai/models?q=zhipuai. Why OpenRouter instead of a direct Zhipu client?Koog's |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have registered an account for the GLM model, and there are several free models available in it. I want to know how to use Koog to connect to the GLM model instead of using the predefined model types provided by Koog.
Beta Was this translation helpful? Give feedback.
All reactions