Pi-style LM authentication helpers for DSPy
Project description
dspy-lm-auth
Pi-style LM authentication helpers for DSPy.
dspy-lm-auth makes it easy to reuse Pi-style credentials with dspy.LM, including ChatGPT Codex subscription auth.
What it does
- reuses Pi credentials from
~/.pi/agent/auth.json - resolves provider config values from:
- literal strings
- environment variable names
!shell commandlookups
- supports OAuth login and token refresh flows for subscription-backed providers
- patches
dspy.LMso model aliases and alternate auth routes work out of the box
Current support
- OpenAI Codex / ChatGPT Plus or Pro subscription
Install
pip install dspy-lm-auth
Or with uv:
uv pip install dspy-lm-auth
Quick start
import dspy
import dspy_lm_auth
# Optional: patch dspy.LM in place.
dspy_lm_auth.install()
# Reuse Pi's ChatGPT Codex login from ~/.pi/agent/auth.json.
lm = dspy.LM("codex/gpt-5.4")
dspy.configure(lm=lm)
print(lm("hello")[0]["text"])
You can also keep the original model string and apply the Codex auth route explicitly:
import dspy_lm_auth
lm = dspy_lm_auth.LM("openai/gpt-5.4", auth_provider="codex")
print(lm("hello")[0]["text"])
Login
If you do not already have credentials stored in Pi's auth file:
import dspy_lm_auth
# Starts the OAuth flow and writes credentials to ~/.pi/agent/auth.json.
dspy_lm_auth.login("codex")
Credential resolution
API key credentials can be stored as:
- a literal value
- an environment variable name
- a shell lookup prefixed with
!
Examples:
{
"some-provider": {
"type": "api_key",
"key": "OPENAI_API_KEY"
}
}
{
"some-provider": {
"type": "api_key",
"key": "!op read op://Private/openai/api_key --no-newline"
}
}
Development
uv sync --extra dev
uv run pytest
uv run ruff check src tests
Roadmap
The package is structured so more Pi-like providers can be added later, for example:
- Anthropic subscription auth
- GitHub Copilot
- Gemini CLI
- Antigravity
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dspy_lm_auth-0.1.0.tar.gz.
File metadata
- Download URL: dspy_lm_auth-0.1.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b9973186e8a9324c75811d25c9d2eacca4fb1c8386a67265ca91e74a56a56c2
|
|
| MD5 |
20b002657d805ef64d0230647e3561bb
|
|
| BLAKE2b-256 |
a0831f0730f98720ffea7b0d6a3cf901c4d3facf6ba730faf3f1e71701891909
|
File details
Details for the file dspy_lm_auth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dspy_lm_auth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86315f231059be5639a6ff1d715ec0ddf2c1e603181b2800f697f03aba47a8cc
|
|
| MD5 |
bcaa3c1d00a8d6575b189c54932f600b
|
|
| BLAKE2b-256 |
691ac35d107bbf25a9bfeadea220531819dded8c88412ae826732f74011ac50a
|