openai-hs: Unofficial OpenAI client

[ bsd3, library, web ] [ Propose Tags ]

Unofficial OpenAI client

[Skip to Readme]


Maintainer's Corner

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],,,
Dependencies aeson, base (>=4.7 && <5), bytestring, casing, cpphs, http-client, http-types, openai-servant (>=0.2.1), servant, servant-client, servant-multipart-client, text [details]
License BSD-3-Clause
Copyright 2021-2022 Alexander Thiemann <>
Author Alexander Thiemann <>
Maintainer Alexander Thiemann <>
Category Web
Home page
Bug tracker
Source repo head: git clone
Uploaded by AlexanderThiemann at 2022-01-21T05:03:47Z
Distributions NixOS:
Downloads 229 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-01-21 [all 1 reports]

Readme for openai-hs-

[back to package description]


Unofficial OpenAI SDK/client for Haskell. It's generated via servant-client from openai-servant with a small amount of hand-written code. Contributions are welcome!


# stack
stack install openai-hs

# cabal
cabal install openai-hs


{-# LANGUAGE OverloadedStrings #-}
import OpenAI.Client

import Network.HTTP.Client
import Network.HTTP.Client.TLS
import System.Environment (getEnv)
import qualified Data.Vector as V

main :: IO ()
main =
  do manager <- newManager tlsManagerSettings
     apiKey <- T.pack <$> getEnv "OPENAI_KEY"
     -- create a openai client that automatically retries up to 4 times on network
     -- errors
     let client = makeOpenAIClient apiKey manager 4
     result <-
         searchDocuments cli (eId firstEngine) $
         { sccrDocuments = V.fromList ["pool", "gym", "night club"]
         , sccrQuery = "swimmer"
     print result


Supported actions:

  • List engines
  • Retrieve engine
  • Create text completion
  • Run semantic search

Running the tests

You can run all tests with stack test. You'll need an OpenAI API Key assigned to the OPENAI_KEY environment variable.