Skip to content

Instantly share code, notes, and snippets.

@iregina
Last active June 18, 2025 06:42
Show Gist options
  • Select an option

  • Save iregina/894b1524b21194f7e6c79cfa6af95624 to your computer and use it in GitHub Desktop.

Select an option

Save iregina/894b1524b21194f7e6c79cfa6af95624 to your computer and use it in GitHub Desktop.
# .roast/initializers/raix.rb
require "raix"
require "faraday"
require "faraday/retry"
Raix.configure do |config|
# Configure the OpenAI client with custom settings
config.openai_client = OpenAI::Client.new(
access_token: ENV.fetch("OPENAI_API_KEY"),
uri_base: ENV.fetch("OPENAI_API_BASE", "https://api.openai.com/v1"),
) do |f|
# Add automatic retry for failed requests
f.request(:retry, {
max: 2,
interval: 0.05,
interval_randomness: 0.5,
backoff_factor: 2,
})
# Enable debug logging when needed
if ENV["DEBUG"]
f.response(:logger, Logger.new($stdout), {
headers: false,
bodies: true,
errors: true
}) do |logger|
logger.filter(/(Bearer) (\S+)/, '\1[REDACTED]')
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment