Skip to content

Commit c5defc7

Browse files
fix: set dummy OPENAI_API_KEY fallback for custom providers and correct Ollama endpoint (#60)
When using --provider custom without --token, the OpenAI SDK raises an error because OPENAI_API_KEY is unset even though local servers like Ollama don't require authentication. Sets a dummy fallback value so the SDK initialises cleanly. Also corrects the README Ollama example from --endpoint /api/generate to --endpoint /v1 — Pydantic-AI uses the OpenAI SDK which appends /chat/completions to the base URL, so the OpenAI-compatible path (/v1) is required, not Ollama's native generate endpoint. Fixes #59
1 parent 55177b9 commit c5defc7

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ codescanai --provider custom --host http://localhost --port 5000 --token your_to
115115
Using locally running [Ollama](https://github.com/ollama/ollama):
116116

117117
```bash
118-
codescanai --provider custom --model llama3 --host http://localhost --port 11434 --endpoint /api/generate --directory path/to/code
118+
codescanai --provider custom --model llama3 --host http://localhost --port 11434 --endpoint /v1 --directory path/to/code
119119
```
120120

121121
### Supported arguments

core/code_scanner/agent_scanner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ def __init__(self, args) -> None:
4141
if args.endpoint:
4242
host_url += args.endpoint
4343
os.environ["OPENAI_BASE_URL"] = host_url
44-
if args.token:
45-
os.environ["OPENAI_API_KEY"] = args.token
44+
# The OpenAI SDK requires a non-empty API key even for local servers that
45+
# don't authenticate. Fall back to a dummy value when no token is supplied.
46+
os.environ["OPENAI_API_KEY"] = args.token if args.token else "dummy"
4647

4748
self.agent = create_agent(
4849
model_str=model_str,

0 commit comments

Comments
 (0)