beginners

NAMAN 2025-10-28T14:21:07.790909Z

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?

NAMAN 2025-11-04T16:18:38.684409Z

Ok I have done that and all of it checks out

NAMAN 2025-11-04T19:00:14.749239Z

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

🔥 1
NAMAN 2025-11-04T19:03:47.749359Z

also u need to do this that way wsl dose not miss the credentials GEMINI_API_KEY="...." clojure -M:nrepl

NAMAN 2025-10-28T14:21:19.467779Z

(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)

👀 1
Ludger Solbach 2025-10-28T14:38:12.693679Z

@cjb?

👀 1
Cameron 2025-10-28T16:58:45.178149Z

@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 🤔

NAMAN 2025-10-28T17:07:57.973109Z

Yes I have tried the demo as is and the value is accessible

Cameron 2025-10-28T17:59:13.091919Z

hm ok, I have a reminder set to circle back after work

👍 1
Cameron 2025-10-31T13:52:30.071689Z

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.