SDKs

Elixir

Patterns Elixir idiomatiques pour Phoenix et OTP

Utilise Req (le client HTTP Elixir moderne) — construit sur Finch, livré avec retries et pooling de connexions.

mix.exs

defp deps do
  [
    {:req, "~> 0.5"}
  ]
end

Configuration

defmodule Thunderbit do
  @api "https://openapi.thunderbit.com/openapi/v1"

  defp client do
    Req.new(
      base_url: @api,
      auth: {:bearer, System.fetch_env!("THUNDERBIT_API_KEY")},
      receive_timeout: 60_000
    )
  end
end

Distill une page

def distill(url) do
  client()
  |> Req.post!(url: "/distill", json: %{url: url})
  |> Map.fetch!(:body)
  |> get_in(["data", "markdown"])
end

Extract de données structurées

def extract(url, schema) do
  client()
  |> Req.post!(url: "/extract", json: %{url: url, schema: schema})
  |> Map.fetch!(:body)
  |> Map.fetch!("data")
end

extract("https://example.com/product/iphone-15-pro", %{
  type: "object",
  properties: %{
    name: %{type: "string"},
    price: %{type: "number"}
  },
  required: ["name", "price"]
})

Batch avec Oban

Pour le fan-out asynchrone, mets les soumissions en file avec Oban et laisse ton endpoint Phoenix gérer le callback webhook :

def submit_batch(urls) do
  client()
  |> Req.post!(url: "/batch/distill", json: %{
    urls: urls,
    webhook: %{
      url: "#{MyApp.Endpoint.url()}/webhooks/distill",
      secret: System.fetch_env!("WEBHOOK_SECRET")
    }
  })
end

Vérifie la signature du webhook dans ton contrôleur Phoenix — voir Webhooks.

Un SDK Elixir officiel est en développement — reviens bientôt.