LLM chat completion
llm_chatGet a reply from any AIMLAPI language model (the model parameter selects it) to a list of chat messages: text, code, reasoning, image understanding for vision models, and function calling with your own tools. For embeddings use embeddings_create; for images, video or music use image_generate, video_generate or audio_generate. Billed to your AIMLAPI balance at the model's price (see model_get). Returns the complete reply: content, role, finish_reason, model, usage (token counts) and tool_calls (the functions the model asked to call, or null); with n > 1 also choices, every reply with its own index, content, finish_reason and tool_calls. A reply that takes longer than about two minutes returns a job_id with status "processing" instead: fetch the reply with job_result.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"model": "<model>",
"messages": "<messages>"
},
"name": "llm_chat"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| n | No | How many alternative replies the model generates (default 1). With n > 1 the tool returns every reply in `choices`, the first one also in `content`; every reply is billed. A model whose card does not list n returns one reply. | |
| seed | No | An integer for best-effort repeatable sampling: the same seed, model and parameters tend to give the same reply. Not every model supports it, and none guarantees it. | |
| stop | No | A string, or a list of strings, at which the model stops writing; the stop text itself is not included in the reply. | |
| model | Yes | AIMLAPI model id or alias, e.g. "gpt-5" or "claude-opus-4-8". Find ids with models_search, models_list or jev_model_search. | |
| tools | No | Functions the model may ask to call, in OpenAI format: [{ "type": "function", "function": { "name": "…", "description": "…", "parameters": { JSON Schema } } }]. The model does not run them: its calls come back in `tool_calls`, and you send each result back as a { "role": "tool", "tool_call_id": "…", "content": "…" } message. These are your own functions, not AIMLAPI Agent Tools (tools_run). Only for models with the `tools` capability. | |
| top_p | No | Nucleus sampling, 0–1: the model picks only among the most likely tokens whose probabilities add up to top_p (0.1 = the top 10%). Omit it for the model default. | |
| stream | No | How the gateway reads the reply from the model: as a stream (true, the default) or in one response (false). This tool returns the complete reply either way; it does not stream to you. | |
| messages | Yes | OpenAI-style chat messages, oldest first; each is an object like { "role": "user"|"assistant"|"system"|"tool", "content": "…" }. For a model with the `vision` capability, `content` can be an array of parts such as { "type": "image_url", "image_url": { "url": "https://…" } }. | |
| provider | No | Pin the request to one upstream provider of the model, e.g. "openai" or "google": only that provider is tried, with no fallback to others, and a parameter it does not support is an error instead of being dropped. Omit it (or "auto") to let AIMLAPI use the primary provider and fall back to others. A provider the model does not have is an error that lists the available ones. | |
| max_tokens | No | Most tokens the model may generate — the older OpenAI name of the limit, kept for compatibility. Same limit as max_completion_tokens: AIMLAPI sends the value under whichever name the provider expects, so the two fields set the same limit; on reasoning models it also covers the hidden reasoning tokens. Set one; if both are set, max_completion_tokens wins. | |
| temperature | No | Sampling temperature, 0–2: higher gives more varied replies, lower more focused and repeatable ones. Omit it for the model default; set temperature or top_p, not both. | |
| tool_choice | No | Whether the model calls one of `tools`: "auto" (the default with tools — the model decides), "none", "required" (it must call one), or { "type": "function", "function": { "name": "…" } } to force that function. | |
| response_format | No | Reply format. { "type": "json_object" } asks for valid JSON; { "type": "json_schema", "json_schema": { "name": "…", "schema": { … }, "strict": true } } asks for JSON that matches the schema. Only for models with the `structured_output` capability; omit it for plain text. | |
| presence_penalty | No | -2 to 2. Positive values lower the chance of any token that has already appeared, which nudges the model toward new topics. Default 0. | |
| reasoning_effort | No | How much a model with the `reasoning` capability thinks before answering: "none", "minimal", "low", "medium", "high", "xhigh" or "max" — more effort is slower and uses more (billed) tokens. Each model accepts its own subset (some have no "none"), and a level the model does not accept is an error. A model without reasoning ignores it, unless `provider` is set. | |
| frequency_penalty | No | -2 to 2. Positive values lower the chance of a token the more often it has already appeared, which reduces word-for-word repetition. Default 0. | |
| max_completion_tokens | No | Most tokens the model may generate — the newer OpenAI name of the limit, preferred. Same limit as max_tokens: AIMLAPI sends the value under whichever name the provider expects, so the two fields set the same limit; on reasoning models it also covers the hidden reasoning tokens. Set one; if both are set, max_completion_tokens wins. |