Hi everyone , I was trying to use grain (`https://github.com/ObneyAI/grain`) specifically trying to get the demo running (`macroexpand-2-demo` 01_hello_world.clj) but I keep running into this issue
RuntimeError: Both structured output format and JSON mode failed. Please choose a model that supports `response_format` argument. Original error: litellm.AuthenticationError: AuthenticationError: OpenrouterException - {"error":{"message":"No auth credentials found","code":401}}
Here's what I've tried:
1. Set the relevant API key (`OPENROUTER_API_KEY` or GOOGLE_API_KEY) using export in my WSL terminal before starting the nREPL.
2. Verified that (System/getenv "...") in the Clojure REPL correctly shows the key.
3. Tried hardcoding the API key directly in the dspy.clj file (snippet in thread ). Still get the 401.
4. Ensured my python.edn points to the absolute path of the Python executable in my venv.
5. Confirmed my API key for [OpenRouter/Google] works using curl
I use windows with wsl to do my Clojure development
Has anyone run into similar issues setting up grain or using dspy/`libpython-clj` with LLM APIs on WSL?Ok I have done that and all of it checks out
ok updating the dspy.clj to (def lm (dspy/LM "gemini/gemini-2.0-flash-exp" :api_key (System/getenv "GEMINI_API_KEY"))) fixed it
also u need to do this that way wsl dose not miss the credentials GEMINI_API_KEY="...." clojure -M:nrepl
(ns ai.obney.extras.dspy
(:require [libpython-clj2.require :refer [require-python]]))
(require-python '[dspy :as dspy])
(def lm #_{:clj-kondo/ignore [:unresolved-namespace]}
(dspy/LM "..."
:api_key "..." ; (getenv or hardcoded)
;; include :api_base if using OpenRouter, remove if direct Gemini
))
#_{:clj-kondo/ignore [:unresolved-namespace]}
(dspy/configure :lm lm)@naman Hm I have not tried this on WSL and do not currently have a way to try it on WSL. Just sanity checking, you tried the demo as is with an open router api key and this is the result? If the value is accessible within Clojure, I'm not sure how or why it would not make it to the python environment 🤔
Yes I have tried the demo as is and the value is accessible
hm ok, I have a reminder set to circle back after work
Hey, so my suggestion would be to start with a tiny DSPy program in python and see if it's catching your environment variable for the API key. That way we can rule out issues at the strictly python level.