Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ RubyLLM.configure do |config|
# Provide keys ONLY for the providers you intend to use.
# Using environment variables (ENV.fetch) is highly recommended.
config.openai_api_key = ENV.fetch('OPENAI_API_KEY', nil)
config.openai_organization_id = ENV.fetch('OPENAI_ORGANIZATION_ID', nil)
config.openai_project_id = ENV.fetch('OPENAI_PROJECT_ID', nil)
config.anthropic_api_key = ENV.fetch('ANTHROPIC_API_KEY', nil)
config.gemini_api_key = ENV.fetch('GEMINI_API_KEY', nil)
config.deepseek_api_key = ENV.fetch('DEEPSEEK_API_KEY', nil)
Expand Down Expand Up @@ -117,6 +119,15 @@ end

This setting redirects requests made with `provider: :openai` to your specified base URL. See the [Working with Models Guide]({% link guides/models.md %}#connecting-to-custom-endpoints--using-unlisted-models) for more details on using custom models with this setting.

## Optional OpenAI Headers

OpenAI supports additional headers for organization and project management:

* `openai_organization_id`: Specifies the billing organization for API usage when multiple organizations are accessible.
* `openai_project_id`: Tracks API usage for a project.

These headers are optional and only need to be set if you want to use organization or project-specific billing.

## Default Models

These settings determine which models are used by the top-level helper methods (`RubyLLM.chat`, `RubyLLM.embed`, `RubyLLM.paint`) when no specific `model:` argument is provided.
Expand Down
4 changes: 3 additions & 1 deletion lib/ruby_llm/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Configuration
# Provider-specific configuration
attr_accessor :openai_api_key,
:openai_api_base,
:openai_organization_id,
:openai_project_id,
:anthropic_api_key,
:gemini_api_key,
:deepseek_api_key,
Expand Down Expand Up @@ -56,7 +58,7 @@ def initialize

def inspect
redacted = lambda do |name, value|
if name.match?(/_key|_secret|_token$/)
if name.match?(/_id|_key|_secret|_token$/)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this, but probably a good idea.

value.nil? ? 'nil' : '[FILTERED]'
else
value
Expand Down
6 changes: 4 additions & 2 deletions lib/ruby_llm/providers/openai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def api_base(config)

def headers(config)
{
'Authorization' => "Bearer #{config.openai_api_key}"
}
'Authorization' => "Bearer #{config.openai_api_key}",
'OpenAI-Organization' => config.openai_organization_id,
'OpenAI-Project' => config.openai_project_id
}.compact
end

def capabilities
Expand Down