haskell-google-genai-client: Auto-generated Gemini API Client for Haskell

[ api, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

Unofficial Haskell client for Google GenAI API, including Gemini.

This library is auto-generated from the OpenAPI specification, using openapi-generator.

Google API reference: https://ai.google.dev/api


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
usekatip

Use the katip package to provide logging (if false, use the default monad-logger package)

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0
Dependencies aeson (>=2.0 && <3), base (>=4.16 && <5), base64-bytestring (>=1.0.0 && <2), bytestring (>=0.11.0 && <1), case-insensitive (>=1.2 && <2), containers (>=0.6 && <0.8), deepseq (>=1.4 && <1.6), exceptions (>=0.10 && <1), http-api-data (>=0.4 && <0.7), http-client (>=0.7 && <0.8), http-client-tls (>=0.3 && <1), http-media (>=0.8 && <0.9), http-types (>=0.12 && <0.13), iso8601-time (>=0.1.3 && <0.2), microlens (>=0.4.3 && <1), monad-logger (>=0.3 && <0.4), mtl (>=2.2.1 && <3), network (>=3.0 && <3.9), random (>=1.1 && <2), safe-exceptions (>=0.1 && <0.2), text (>=1.2 && <3), time (>=1.5 && <2), transformers (>=0.5.0.0 && <1), unordered-containers (>=0.2 && <1), vector (>=0.12 && <0.14) [details]
License MIT
Copyright 2025 Sonowz
Author SoonHo Seo
Maintainer dnsdhrj123@gmail.com
Category API
Home page https://github.com/sonowz/haskell-google-genai-client#readme
Bug tracker https://github.com/sonowz/haskell-google-genai-client/issues
Source repo head: git clone https://github.com/sonowz/haskell-google-genai-client
Uploaded by sonowz at 2025-06-04T01:55:38Z
Distributions
Downloads 2 total (2 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for haskell-google-genai-client-0.1.0

[back to package description]

Haskell Google GenAI Client

Unofficial low-level Haskell client for the Google Gemini API (also known as GenAI API or Generative Language API).

This library provides a type-safe way to interact with Google's Gemini API services directly from your Haskell code.

Note

  • The code is automatically generated from the OpenAPI specification using openapi-generator.
  • APIs include text/image/audio generation, embeddings, model tuning, semantic retrieval API, and more. See Google API reference for full details.

Development

First, run nix develop to enter the development shell. Non-Nix users should install the dependencies such as openapi-generator and pre-commit.

# Generate the Haskell client code from the OpenAPI specification
./run-generator.sh
# Format the code and check for linting issues
pre-commit run --all-files
# Build the project
cabal build
# Run the tests
cabal test

Example Usage

Here is a working example that uses 'generateContent' API to generate text using Gemini model:

{-# LANGUAGE OverloadedStrings #-}
import GenAI.Client
import Network.HTTP.Client (responseBody)
import Network.HTTP.Client.TLS (newTlsManager)
import Network.HTTP.Types (QueryItem)
import Data.ByteString.Lazy qualified as LBS

apiKeyParam :: QueryItem
apiKeyParam = ("key", Just "<GEMINI_API_KEY>")

model :: Model2
model = Model2 "gemini-2.0-flash-001"

requestBody :: GenerateContentRequest
requestBody = mkGenerateContentRequest [content] "gemini-2.0-flash-001" where
  content = mkContent { contentParts = Just [textPart] }
  textPart = mkPart { partText = Just query }
  query = "What is the capital of Korea?"

request :: ClientRequest GenerateContent MimeJSON GenerateContentResponse MimeJSON
request = flip addQuery [apiKeyParam] $ flip setBodyParam requestBody $ generateContent model

main :: IO ()
main = do
  config <- withStdoutLogging =<< newConfig
  manager <- newTlsManager
  response <- dispatchLbs manager config request
  LBS.putStr $ responseBody response

Running code above will produce:

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "The capital of South Korea is **Seoul**.\n"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "avgLogprobs": -0.024313041940331459
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 7,
    "candidatesTokenCount": 8,
    "totalTokenCount": 15,
    "promptTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 7
      }
    ],
    "candidatesTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 8
      }
    ]
  },
  "modelVersion": "gemini-2.0-flash-001",
  "responseId": "ZQc_aPa7JcXWnvgP3LDNsAw"
}