API key by host
The rule, in order
Section titled “The rule, in order”-
apiKeyis set: send it, and nothing else. -
Else
apiKeyEnvis set: read that env var (the variable’s name, never its value, goes in your code). -
Else read only the env var of the
baseUrlhost, over https:host env var api.openai.comOPENAI_API_KEYapi.anthropic.comANTHROPIC_API_KEYopenrouter.ai(and subdomains)OPENROUTER_API_KEY -
Any other host, or plain
http, withoutapiKey/apiKeyEnv: an error. There is no cross-provider fallback.
listModels follows the same rule.
A local server and a proxy
Section titled “A local server and a proxy”// local server that ignores the key: any placeholderconst local = createClient({ baseUrl: "http://localhost:11434/v1", style: "openai", model: "llama3", apiKey: "unused" })// proxy: name the env var to readconst proxy = createClient({ baseUrl: "https://llm.internal/v1", style: "openai", model: "m", apiKeyEnv: "INTERNAL_LLM_KEY" })local = create_client(base_url="http://localhost:11434/v1", style="openai", model="llama3", api_key="unused")proxy = create_client(base_url="https://llm.internal/v1", style="openai", model="m", api_key_env="INTERNAL_LLM_KEY")local := toolnexus.CreateClient(toolnexus.ClientOptions{ BaseURL: "http://localhost:11434/v1", Style: toolnexus.StyleOpenAI, Model: "llama3", APIKey: "unused",})proxy := toolnexus.CreateClient(toolnexus.ClientOptions{ BaseURL: "https://llm.internal/v1", Style: toolnexus.StyleOpenAI, Model: "m", APIKeyEnv: "INTERNAL_LLM_KEY",})LlmClient local = LlmClient.create(new LlmClient.Options() .baseUrl("http://localhost:11434/v1").style("openai").model("llama3").apiKey("unused"));LlmClient proxy = LlmClient.create(new LlmClient.Options() .baseUrl("https://llm.internal/v1").style("openai").model("m").apiKeyEnv("INTERNAL_LLM_KEY"));var local = LlmClient.Create(new LlmClient.Options { BaseUrl = "http://localhost:11434/v1", Style = "openai", Model = "llama3", ApiKey = "unused" });var proxy = LlmClient.Create(new LlmClient.Options { BaseUrl = "https://llm.internal/v1", Style = "openai", Model = "m", ApiKeyEnv = "INTERNAL_LLM_KEY" });local = Toolnexus.Client.create(base_url: "http://localhost:11434/v1", style: "openai", model: "llama3", api_key: "unused")proxy = Toolnexus.Client.create(base_url: "https://llm.internal/v1", style: "openai", model: "m", api_key_env: "INTERNAL_LLM_KEY")(def local (client/create-client {:base-url "http://localhost:11434/v1" :style "openai" :model "llama3" :api-key "unused"}))(def proxy (client/create-client {:base-url "https://llm.internal/v1" :style "openai" :model "m" :api-key-env "INTERNAL_LLM_KEY"}))let local = create_client(ClientOptions { base_url: "http://localhost:11434/v1".into(), style: Style::OpenAI, model: "llama3".into(), api_key: "unused".into(), ..Default::default()});let proxy = create_client(ClientOptions { base_url: "https://llm.internal/v1".into(), style: Style::OpenAI, model: "m".into(), api_key_env: "INTERNAL_LLM_KEY".into(), ..Default::default()});A hosted provider needs neither: baseUrl: "https://openrouter.ai/api/v1" with
OPENROUTER_API_KEY in the environment works as before.
The full rule, with runnable examples, is on each port’s API page, e.g. JavaScript, Python, Go, Java, C#, Elixir, Clojure.