HuggingfaceClient.Client (huggingface_client v0.1.0)

Copy Markdown View Source

Represents a configured HuggingFace Inference client.

Holds the access token and default options that are merged with per-call options.

Creating a client

client = HuggingfaceClient.Client.new("hf_your_token")

# With defaults
client = HuggingfaceClient.Client.new("hf_your_token",
  provider: "groq",
  bill_to: "my-org"
)

Using with an inference endpoint

client = HuggingfaceClient.Client.endpoint(
  "hf_token",
  "https://xyz.eu-west-1.aws.endpoints.huggingface.cloud/gpt2"
)

Option schema

OptionTypeDescription
:providerstringDefault provider (e.g. "groq", "together")
:bill_tostringHF organisation to bill the request to
:endpoint_urlstringCustom endpoint URL (overrides provider routing)
:retry_on_503booleanAuto-retry on 503 responses (default: true)
:req_optskeywordExtra options forwarded to Req

Summary

Functions

Creates a Client tied to a specific inference endpoint URL.

Merges client defaults with per-call options.

Creates a new Client with the given access token and options.

Validates and returns the NimbleOptions schema for documentation.

Types

t()

@type t() :: %HuggingfaceClient.Client{
  access_token: String.t() | nil,
  bill_to: String.t() | nil,
  endpoint_url: String.t() | nil,
  provider: String.t() | nil,
  req_opts: keyword(),
  retry_on_503: boolean()
}

Functions

endpoint(access_token, endpoint_url, opts \\ [])

@spec endpoint(String.t() | nil, String.t(), keyword()) :: t()

Creates a Client tied to a specific inference endpoint URL.

Equivalent to calling client.endpoint(url) in the JS package.

merge_opts(client, call_args)

@spec merge_opts(t(), map()) :: map()

Merges client defaults with per-call options.

Per-call options always take precedence.

new(access_token, opts \\ [])

@spec new(
  String.t() | nil,
  keyword()
) :: t()

Creates a new Client with the given access token and options.

Raises InputError if options are invalid.

options_schema()

@spec options_schema() :: NimbleOptions.t()

Validates and returns the NimbleOptions schema for documentation.