Skip to main content

Configuring the SDKs

Both clients can be configured globally once, or per instance. This page covers where that initialization belongs and which options you should set rather than inherit.

Settings

Both SDKs accept the same four things, under language-appropriate names.

SettingRubyNode.jsDefault
API keyapi_keyapiKeynone — required
Endpointapi_urlapiUrla Render-hosted URL, not bibleql.org
Fallback translationdefault_translationdefaultTranslationeng-web
Timeouttimeout (seconds)timeout (milliseconds)30s / 30000ms

Note the timeout unit differs between the two.

Always set the endpoint explicitly

Both SDKs currently default api_url / apiUrl to a Render-hosted hostname rather than https://bibleql.org/graphql. If you leave it unset, your traffic goes somewhere other than the canonical endpoint. Pin it in your initializer.

Where to initialize

In a Rails app, configure once in an initializer:

config/initializers/bibleql.rb
require "bibleql"

BibleQL.configure do |config|
config.api_key = ENV.fetch("BIBLEQL_API_KEY")
config.api_url = "https://bibleql.org/graphql"
config.default_translation = "eng-web"
config.timeout = 30
end

Then anywhere in the app:

BibleQL.client.passage("John 3:16")

ENV.fetch without a default is deliberate — it fails loudly at boot if the key is missing, rather than at the first request in production.

Using Rails credentials instead

If you keep secrets in config/credentials.yml.enc rather than the environment:

config/initializers/bibleql.rb
BibleQL.configure do |config|
config.api_key = Rails.application.credentials.bibleql!(:api_key)
config.api_url = "https://bibleql.org/graphql"
end

Edit them with bin/rails credentials:edit:

bibleql:
api_key: bql_live_...

Per-instance clients

Global configuration is convenient but shared. For a distinct translation, a different timeout, or an isolated client in tests, build one directly:

client = BibleQL::Client.new(
api_key: ENV.fetch("BIBLEQL_API_KEY"),
api_url: "https://bibleql.org/graphql",
default_translation: "spa-rv1909"
)

A per-instance client ignores the global configuration, which makes it the better choice in tests — no global state to reset between examples.

Plain Ruby, no Rails

There is no initializer directory, so configure once at load time, before first use:

require "bibleql"

BibleQL.configure do |config|
config.api_key = ENV.fetch("BIBLEQL_API_KEY")
config.api_url = "https://bibleql.org/graphql"
end

Choosing a default translation

default_translation / defaultTranslation only applies when a call omits the translation. It does not restrict anything — any call can pass a different one.

Set it to whatever your application shows most often. If you serve several languages, prefer passing translation explicitly at each call site so the behaviour does not depend on configuration read elsewhere.

Timeouts

The defaults (30 seconds) are generous for most queries. Two things worth knowing:

  • semanticSearch calls an external embedding service and is the slowest query in the API. If you use it behind a user-facing request, a shorter timeout plus a fallback beats a hung page.
  • Large concordance pages take longer than a verse lookup. Reduce first before you raise the timeout.

Verifying your setup

A cheap query that touches no Bible text:

translations = BibleQL.client.translations
puts "#{translations.size} translations available"

If the key is wrong you get an authentication error immediately — see Errors for what each failure looks like, and SDKs for the exception class each one maps to.

Use a test key locally

Point development at a bql_test_ key. Production refuses test-environment keys, so a key leaked from a laptop or a CI log cannot spend your live quota. See API Keys.