Skip to main content

Configuring the SDKs

The Ruby and Node clients can be configured globally once, or per instance; the Python client is always per instance. This page covers where that initialization belongs and which options you should set rather than inherit.

Settings​

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

SettingRubyNode.jsPythonDefault
API keyapi_keyapiKeyapi_keynone — required (Python falls back to BIBLEQL_API_KEY)
Endpointapi_urlapiUrlapi_urlRuby/Node: a Render-hosted URL, not bibleql.org. Python: https://bibleql.org/graphql
Fallback translationdefault_translationdefaultTranslationdefault_translationeng-web
Timeouttimeout (seconds)timeout (milliseconds)timeout (seconds)30s / 30000ms / 30s

Note the timeout unit is milliseconds in Node and seconds in the other two.

Always set the endpoint explicitly in Ruby and Node

Those 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. The Python client already defaults to the canonical endpoint.

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. (Python's semantic_search is the one exception: it ignores the default and lets the API choose a translation with embeddings.)

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.