← all modules

Std.Ai.Provider

Std.Ai.Provider

Types
  type alias Direct = { endpoint : String , apiKey : Secret , model : String }
  type alias CustomImpl
  type Provider
  type alias Message = { role : String , content : String }
  type alias Usage = { promptTokens : Int , completionTokens : Int , totalTokens : Int }
  type alias ChatResponse = { content : String , usage : Usage }
  type alias Request = { model : String , messages : List Message }
  type alias RawMessage = { content : String }
  type alias RawChoice = { message : RawMessage }
  type alias RawUsage = { prompt_tokens : Int , completion_tokens : Int , total_tokens : Int }
  type alias RawResponse = { choices : List RawChoice , usage : RawUsage }
  type alias ToolSpec
  type alias ToolCall
  type alias ToolResponse
  type Turn = Say Message | Called (List ToolCall) | Returned ToolCall String
  type alias PriceBook

Values
  assistant : String -> Message
  chat : Provider -> List Message -> Task Error ChatResponse
      Send a chat and get the assistant text plus token usage. Fails with a
  chatTools : Provider -> List Turn -> List ToolSpec -> Task Error ToolResponse
      Like `chat`, but advertises `tools` and returns any `tool_calls` the model
  compatible : String -> Secret -> String -> Provider
      Any OpenAI-compatible endpoint — a gateway, vLLM, or a local llama.cpp server
  cost : PriceBook -> Usage -> Money
      The money cost of a usage under a price book: tokens/1000 × the per-1k rate,
  custom : (List Message -> Task Error ChatResponse) -> Provider
      Bring your own backend: wrap any `List Message -> Task Error ChatResponse`
  customTools : (List Message -> Task Error ChatResponse) -> (List Turn -> List ToolSpec -> Task Error ToolResponse) -> Provider
      Like `custom`, but the provider ALSO implements native tool-calling: supply
  freePriceBook : Money.Currency -> PriceBook
      A zero-cost book, for a local model or a test.
  openai : Secret -> String -> Provider
      The hosted OpenAI chat-completions endpoint.
  priceBook : Money.Currency -> String -> String -> Result Error PriceBook
      Build a price book from decimal-string rates (e.g. "0.00015" per 1k input
  router : (List Message -> Provider) -> Provider
      A multi-provider ROUTER: a `Provider` that, per call, picks a concrete backend
  system : String -> Message
  user : String -> Message