OpenRouter
Connect to OpenRouter with one API key, choose a model ID from its catalog, and use it with the standard nimgent APIs.
Make a request
Section titled “Make a request”import std/osimport nimgentimport nimgent/providers/openrouter
let model = openRouter(getEnv("OPENROUTER_API_KEY")).model( "deepseek/deepseek-v4-flash-0731")echo generateText(model, prompt = "Say hello in one sentence.").textSet OPENROUTER_API_KEY before you run the program.
Control OpenRouter routing
Section titled “Control OpenRouter routing”Use OpenRouterOptions to select providers or control fallback behavior for an OpenRouter request.
import std/options
let settings = ProviderOptions( openrouter: OpenRouterOptions( routing: some(OpenRouterRouting( sort: some("latency"), allowFallbacks: some(false)))))
let response = generateText(model, prompt = "Summarize this.", providerOptions = settings)OpenRouterRouting also supports order, only, ignore, and requireParameters.
Next steps
Section titled “Next steps”See Settings for portable controls, or Middleware and routing to route models in your own application.