Skip to main content
Shipfastai’s LLM abstraction layer lets you swap providers — OpenAI, Anthropic, or Google Gemini — by changing a single provider field in your API request. Your application code never needs to know which underlying SDK is in use. The get_llm_provider factory in app/packages/ai/llm.py instantiates the right client, passes the correct API key from your environment, and returns a consistent ChatResponse regardless of which model generated it.

Supported providers

Shipfastai ships with three first-class provider implementations inside products/pro/backend/app/packages/ai/llm.py: All three implement the same abstract LLMProvider interface with chat() and stream_chat() methods, so switching providers requires no changes to your route handlers.

Configuring OpenAI

1

Set your API key

Add your OpenAI API key to your backend .env file:
.env
2

Send requests using the openai provider

Pass "provider": "openai" in your request body. You can optionally specify a model; if you omit it the default gpt-4o is used.
POST /api/ai/chat

Configuring Anthropic

1

Set your API key

.env
2

Send requests using the anthropic provider

POST /api/ai/chat
The AnthropicProvider automatically extracts system-role messages and passes them to Anthropic’s system parameter, so your request format is identical across providers.

Configuring Google Gemini

1

Set your API key

.env
2

Send requests using the gemini provider

POST /api/ai/chat

Switching providers at runtime

Because the provider and model fields are part of each request body, you can switch providers on a per-request basis without redeploying. This is useful for A/B testing models or falling back to a cheaper provider under load.
POST /api/ai/chat
You can also enable streaming for any provider by adding "stream": true to the request body. The endpoint returns a text/event-stream response where each event is a JSON object { "token": "..." }, terminated by data: [DONE].
POST /api/ai/chat (streaming)

Extending with a new provider

All providers inherit from the abstract base class LLMProvider defined in products/pro/backend/app/packages/ai/llm.py. To add a new provider, you implement two async methods and register the provider in the factory function.
1

Create your provider class

Add a new class that extends LLMProvider and implements chat() and stream_chat():
products/pro/backend/app/packages/ai/llm.py
2

Register the provider in the factory

Update get_llm_provider() to handle your new provider string:
products/pro/backend/app/packages/ai/llm.py
3

Export the class and add the env var

Add GroqProvider to the __all__ list in packages/ai/__init__.py, then add GROQ_API_KEY to your .env file.
Because the chat endpoint in app/api/ai/chat.py delegates entirely to get_llm_provider(), your new provider is immediately available to all routes — including streaming completions — without any further changes.