Sycophant.Transport (sycophant v0.4.2)

Copy Markdown

HTTP transport layer built on Tesla.

Constructs a fresh Tesla client per request and executes HTTP POSTs, mapping HTTP status codes to Splode error structs. Auth middleware is injected by the caller via :auth_middlewares, keeping Transport agnostic about authentication schemes.

Error Mapping

  • 401 -> AuthenticationFailed
  • 404 -> ModelNotFound
  • 429 -> RateLimited (with Retry-After parsing)
  • 400-499 -> BadRequest
  • 500+ -> ServerError

Summary

Functions

Sends a synchronous HTTP POST and returns the decoded body.

Sends a synchronous HTTP POST and returns the decoded body along with response headers.

Sends a streaming HTTP POST using SSE and yields the event stream to on_event.

Sends a streaming HTTP POST for binary event-stream protocols and yields raw chunks to on_chunks.

Functions

call(payload, opts)

@spec call(
  map(),
  keyword()
) :: {:ok, map()} | {:error, Splode.Error.t()}

Sends a synchronous HTTP POST and returns the decoded body.

call_raw(payload, opts)

@spec call_raw(
  map(),
  keyword()
) :: {:ok, {map(), [{String.t(), String.t()}]}} | {:error, Splode.Error.t()}

Sends a synchronous HTTP POST and returns the decoded body along with response headers.

stream(payload, opts, on_event)

@spec stream(map(), keyword(), (Enumerable.t() -> term())) ::
  {:ok, term()} | {:error, Splode.Error.t()}

Sends a streaming HTTP POST using SSE and yields the event stream to on_event.

stream_binary(payload, opts, on_chunks)

@spec stream_binary(map(), keyword(), (Enumerable.t() -> term())) ::
  {:ok, term()} | {:error, Splode.Error.t()}

Sends a streaming HTTP POST for binary event-stream protocols and yields raw chunks to on_chunks.