Skip to content

Model providers

Naming a model

Name the model as <org>/<name> when you build the agent. The name is the one its maker gives it: the official API id for Claude, GPT and Gemini, the Hugging Face repo id for open-weight models, and the API id for a model with no repo, such as EXAONE’s k-exaone_v2.5. The same name works whichever way the model runs.

Models Org Example
Claude anthropic anthropic/claude-haiku-5-5
GPT openai openai/gpt-6-luna
Gemini google google/gemini-3.1-pro
DeepSeek deepseek-ai deepseek-ai/DeepSeek-V3.2
Kimi moonshotai moonshotai/Kimi-K2-Thinking
GLM zai-org zai-org/GLM-4.6
Qwen Qwen Qwen/Qwen3-235B-A22B-Instruct-2507
EXAONE LGAI-EXAONE LGAI-EXAONE/k-exaone_v2.5
agent = await AgentBuilder("anthropic/claude-haiku-5-5").build()

For a CLI, the org alone (anthropic) runs the CLI’s default model.

Backends

Each org’s models run on one backend:

Backend Runs the model through Needs
cli The org’s CLI: Claude Code (claude), Codex (codex) or Gemini CLI (gemini) The CLI on PATH, logged in
api The org’s own API ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY, DEEPSEEK_API_KEY, KIMI_API_KEY (or MOONSHOT_API_KEY), ZAI_API_KEY, DASHSCOPE_API_KEY (Qwen) or EXAONE_API_KEY
bedrock Amazon Bedrock AWS_BEARER_TOKEN_BEDROCK; the region from AWS_REGION, then AWS_DEFAULT_REGION, else us-east-1
openrouter OpenRouter OPENROUTER_API_KEY
self-hosted A server you run yourself, through the OpenAI-compatible Chat Completions API it serves: vLLM, llama-server, Ollama, LM Studio or SGLang SELF_HOSTED_BASE_URL, and SELF_HOSTED_API_KEY if the server wants one

By default, Claude, GPT and Gemini run through their CLIs, and the other orgs through their own APIs. Keys are read from the environment when a model is built, so set them before that.

cli and api know the orgs in Naming a model. The other backends build a model for any org, meta-llama or mistralai as well. Such an org has no backend until you set one with set_lang_model_provider; building its model before that fails. Which backends serve which org:

Org cli api bedrock openrouter self-hosted
anthropic ✓ ✓ ✓ ✓ ✓
openai ✓ ✓ ✓ ✓ ✓
google ✓ ✓ ✓ ✓
deepseek-ai, moonshotai, zai-org, Qwen, LGAI-EXAONE ✓ ✓ ✓ ✓
any other org ✓ ✓ ✓

Bedrock and OpenRouter name models their own way. Ailoy looks your model up in their catalogs, so you still write anthropic/claude-haiku-5-5, and the catalog decides which Bedrock or OpenRouter id it runs as. A server you run yourself is asked what it serves too; A server of your own says how the id is found, and how to name it yourself when the server calls the model something else.

Choosing a backend

Set an org’s backend with set_lang_model_provider (setLangModelProvider in Node.js) before building an agent. It applies to every model of that org built afterwards.

import ailoy
ailoy.set_lang_model_provider("anthropic", "api")
agent = await AgentBuilder("anthropic/claude-haiku-5-5").build()

remove_lang_model_provider (removeLangModelProvider) takes the org’s provider away, after which its models can’t be built.

A server of your own

self-hosted reads its server from the environment, one for the whole process. To name the server per org, give set_lang_model_provider the backend together with the server’s URL, and an API key if the server wants one. Two servers, say vLLM for code and Ollama for chat, are two orgs:

ailoy.set_lang_model_provider("Qwen", {"backend": "self-hosted", "base_url": "http://gpu-box:8000/v1", "api_key": "..."})
ailoy.set_lang_model_provider("meta-llama", {"backend": "self-hosted", "base_url": "http://localhost:11434/v1", "models": {"Llama-3.3-70B-Instruct": "llama3.3:70b"}})
coder = await AgentBuilder("Qwen/Qwen3-Coder-30B-A3B-Instruct").build()
chat = await AgentBuilder("meta-llama/Llama-3.3-70B-Instruct").build()

The model keeps its name whatever the server calls it. When a model is built, Ailoy finds the id to send in three steps and takes the first that gives one: models (with_model in Rust), which maps a name to the id the server serves it as; the server’s own list at <base_url>/models, where an id equal to <org>/<name> or to <name> alone counts, ignoring case; and the desc as you wrote it. So vLLM, which serves Hugging Face repo ids, needs nothing; LM Studio lists qwen/qwen3-0.6b and is sent that for Qwen/Qwen3-0.6B; and Ollama’s llama3.3:70b is nothing like Llama-3.3-70B-Instruct, so it is mapped, as above. get_lang_model_provider answers self-hosted.

Another endpoint that serves the OpenAI-compatible Chat Completions API, such as a LiteLLM gateway or Together’s API, runs on self-hosted the same way: its URL as base_url and its key as api_key.

Model options

Two options go to every backend:

Option Builder method Description
thinking_effort thinking_effort (thinkingEffort) How much the model thinks before it answers: low, medium or high. Unset, the model’s default.
output_schema output_schema (outputSchema) A JSON schema the model’s answers must match.
agent = await (
AgentBuilder("openai/gpt-6-luna")
.thinking_effort("high")
.output_schema({"type": "object", "properties": {"answer": {"type": "string"}}, "required": ["answer"]})
.build()
)

On self-hosted, and for EXAONE on api, thinking_effort is sent two ways, since servers read different ones: as reasoning_effort (low, medium or high), the field OpenAI’s Chat Completions grades thinking by, and as the chat template’s enable_thinking (and thinking) in chat_template_kwargs, which turns thinking on rather than grading it. output_schema is sent as a json_schema response_format. vLLM reads chat_template_kwargs and response_format, and its documentation says it hands reasoning_effort to the chat template, turning enable_thinking on with it. What the other servers do with them, measured on 2026-11-09 with Qwen3-0.6B on each local server and k-exaone_v2.5 on EXAONE’s API, a schema with additionalProperties: false telling enforcement from obedience:

Server reasoning_effort chat_template_kwargs response_format Thinking comes back as
llama-server (llama.cpp build 11146) Not read: "bogus" is accepted too Read: enable_thinking: false switched the thinking off Enforced reasoning_content
Ollama 0.40.12 Read, as "bogus" is refused, but low, medium and high left Qwen3’s thinking as it was Ignored Enforced reasoning
LM Studio 0.4.26 Read, as "bogus" is refused, but low, medium and high left Qwen3’s thinking as it was Ignored Enforced, with no thinking while the reply is structured reasoning_content
EXAONE API (k-exaone_v2.5) Read, as "bogus" is refused, medium included; on one counting problem the thinking did not follow it, low taking 991 to 1728 reasoning tokens over six runs and high 1054 to 2131 over four enable_thinking: false left the model thinking, with the thinking and its </think> in the reply Enforced reasoning_content

So with Qwen3, thinking_effort changes nothing on llama-server, Ollama or LM Studio: the model thinks as its template defaults. EXAONE always thinks, and with thinking_effort unset it runs at its own default effort, which its documentation gives as max. SGLang has not been measured.

Running a model without an agent

LangModel builds a model the way an agent does, and runs it on a conversation you give it: no tools are called and no history is kept. infer returns the whole reply as a MessageOutput, and infer_stream (inferStream) yields MessageDeltaOutputs as the model writes.

from ailoy import LangModel
model = await LangModel.create("anthropic/claude-haiku-5-5")
messages = [{"role": "user", "contents": [{"type": "text", "text": "Hi"}]}]
output = await model.infer(messages)
async for delta in model.infer_stream(messages, options={"thinking_effort": "low"}):
...

Tools, if you pass them, are only described to the model: its tool calls come back in the reply for you to run.

Bringing your own model

An org can also be served by your own code. Instead of a backend name, give set_lang_model_provider a factory: it’s called with the org and the name after the slash (None/null when the model is named by the org alone) and returns the model. The model has

  • infer(messages, tools, options), returning a MessageOutput (or, in Python and Node.js, an awaitable or promise of one), and optionally
  • infer_stream(messages, tools, options) (inferStream), yielding MessageDeltaOutputs. Without it, streaming gives infer’s reply as one delta.

The factory may also return a LangModel, to serve the org with a model from another org.

class Echo:
def __init__(self, name):
self.name = name
async def infer(self, messages, tools, options):
text = messages[-1]["contents"][0]["text"]
return {
"message": {"role": "assistant", "contents": [{"type": "text", "text": text}]},
"finish_reason": {"type": "stop"},
}
ailoy.set_lang_model_provider("mine", lambda org, name: Echo(name))
agent = await AgentBuilder("mine/echo").build()

In Python and Node.js the factory itself must return the model directly, not an awaitable or promise of it. The model’s methods are called with the messages, tools and options as dicts or objects, the same shapes the message format describes.

Troubleshooting

What you see Why, and what to do
failed to start the claude CLI (or codex, gemini), on the first turn The CLI isn’t installed, or isn’t on the PATH of your program. Install it (With a CLI login), or switch the org to api.
The CLI’s own error on the first turn, such as Claude Code’s “Not logged in” Log in: claude auth login, codex login, or run gemini and sign in. Codex is read from its auth.json, so a login kept in the system keyring (cli_auth_credentials_store) isn’t found.
ANTHROPIC_API_KEY is not set (or another …_API_KEY), at build() Set the variable before building the agent; a blank one counts as unset. Backends lists each org’s variable.
'<org>' has no CLI, or '<org>' has no API of its own Only anthropic, openai and google have a CLI, and api knows only the orgs in Naming a model. Use bedrock, openrouter or self-hosted for any other.
no provider set for lang model org '<org>' The org has no default backend. Set one with set_lang_model_provider first.
AWS_BEARER_TOKEN_BEDROCK is not set Bedrock is reached with a bearer token, not AWS access keys or a profile. Set the token.
Bedrock request failed with status … on the first turn The region is wrong, as us-east-1 is used when neither AWS_REGION nor AWS_DEFAULT_REGION is set, or Bedrock doesn’t serve the model there. Ailoy builds an id for any model, so a model Bedrock lacks, such as Gemini, fails only when it is called.
SELF_HOSTED_BASE_URL is not set Set it, or give the server per org with set_lang_model_provider (A server of your own).
chat completions request failed with status 404: … The base_url is missing its /v1. Ailoy adds /chat/completions to the URL as given.
A connection error naming <base_url>/chat/completions on the first turn The server isn’t running, or the host or port is wrong. build() still succeeds and only logs listing the models at <base_url>/models failed.