Skip to content

Support multiple AI providers (OpenAI-compatible API)#4

Open
aliciapaz wants to merge 2 commits into
mainfrom
feature/multi-provider-support
Open

Support multiple AI providers (OpenAI-compatible API)#4
aliciapaz wants to merge 2 commits into
mainfrom
feature/multi-provider-support

Conversation

@aliciapaz
Copy link
Copy Markdown

Context

The gem was hardcoded to OpenAI's proprietary Responses API (client.responses.create()), making it impossible to use with other AI providers like Minimax, Ollama, Groq, or any OpenAI-compatible service. Users who don't use OpenAI were locked out entirely.

Closes #3

What Changed

Switched the AI layer from OpenAI's Responses API to the standard Chat Completions API, which is the universal interface that all OpenAI-compatible providers implement.

Key files modified:

  • templates/config.js — Provider-agnostic config: reads AI_API_KEY (falls back to OPENAI_API_KEY), supports AI_BASE_URL for custom endpoints, default model changed to gpt-4o
  • templates/ai.js — Replaced client.responses.create()client.chat.completions.create(), updated response parsing (resp.choices[0].message.content instead of resp.output_text), added null-content guard for truncated/refused responses
  • install_generator.rb — Updated post-install instructions to reference AI_API_KEY and AI_BASE_URL
  • README.md — Updated requirements, setup steps, config table, and "How it works" section
  • agent_e2e.gemspec — Updated summary and description

Notable decisions:

  • Kept the openai npm package as the SDK — it natively supports custom baseURL, so no new dependencies needed
  • OPENAI_API_KEY is still supported as a fallback so existing users don't break
  • Added explicit error when AI_API_KEY is missing (previously the OpenAI SDK would throw an opaque error)

How to Test

  1. OpenAI (default): Set AI_API_KEY=sk-... in .env, run bin/e2e — should work identically to before
  2. Backward compat: Set OPENAI_API_KEY=sk-... (old var name) — should still work via fallback
  3. Custom provider: Set AI_API_KEY, AI_BASE_URL, and AI_MODEL for a compatible provider (e.g., Ollama at http://localhost:11434/v1)
  4. Missing key: Remove both env vars — should get a clear error message and exit code 1
  5. Null response: If the model returns content: null (e.g., token limit hit), should get "AI returned empty response" error instead of a crash

Deployment Tasks

None

🤖 Generated with Claude Code

aliciapaz and others added 2 commits March 13, 2026 17:22
Switch from OpenAI's proprietary Responses API to the standard Chat
Completions API so any OpenAI-compatible provider (Minimax, Ollama,
Groq, Together AI, etc.) can be used as the AI backend.

- Replace client.responses.create() with client.chat.completions.create()
- Add AI_API_KEY env var (with OPENAI_API_KEY fallback for existing users)
- Add AI_BASE_URL env var to point at any compatible endpoint
- Guard against null response content with a clear error message
- Update README, gemspec, and generator instructions

Closes #3

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multiple AI providers (OpenAI, Minimax, OpenAI-compatible APIs)

1 participant