SDKs
Ruby
Idiomatic Ruby patterns for the Thunderbit Open API
Use Net::HTTP (built-in) or Faraday for middleware-style retries and timeouts. Both work — Net::HTTP shown below.
Configure
require 'net/http'
require 'json'
require 'uri'
API = 'https://openapi.thunderbit.com/openapi/v1'
HEADERS = {
'Authorization' => "Bearer #{ENV.fetch('THUNDERBIT_API_KEY')}",
'Content-Type' => 'application/json'
}.freeze
def post(path, body)
uri = URI("#{API}#{path}")
res = Net::HTTP.post(uri, body.to_json, HEADERS)
raise res.body if res.code.to_i >= 400
JSON.parse(res.body)
endDistill a page
result = post('/distill', { url: 'https://thunderbit.com/playground' })
puts result['data']['markdown']Extract structured data
result = post('/extract', {
url: 'https://example.com/product/iphone-15-pro',
schema: {
type: 'object',
properties: {
name: { type: 'string' },
price: { type: 'number' }
},
required: %w[name price]
}
})
puts result['data']Batch + Sidekiq
For async fan-out, queue submissions and let Sidekiq workers handle webhook callbacks:
class DistillBatchJob
include Sidekiq::Worker
def perform(urls)
job = post('/batch/distill', {
urls: urls,
webhook: {
url: "#{ENV['APP_HOST']}/webhooks/distill",
secret: ENV['WEBHOOK_SECRET']
}
})
Rails.logger.info "Batch submitted: #{job['data']['id']}"
end
endVerify the webhook signature in your Rails controller — see Webhooks.
An official Ruby SDK is in development — check back soon.