class RubyLLM::Context

A Context is an isolated configuration scope. It offers the same entry points as the top-level RubyLLM module but reads from its own Configuration copy instead of the global one, which suits multi-tenant applications and per-request overrides.

Contexts are created with RubyLLM.context:

ctx = RubyLLM.context do |config|
  config.openai_api_key = ENV['ANOTHER_PROVIDER_KEY']
  config.request_timeout = 180
end

chat = ctx.chat(model: 'gpt-5.4')
chat.ask "Process this with another provider..."

The global configuration is left untouched.

Batch submission uses each chat’s own configuration (a chat carries the config it was built with), so there is no context entry point for it. To look up an existing batch, where no chats carry the config, pass a context to Batch.find:

RubyLLM::Batch.find(id, provider: :anthropic, context: ctx)