This commit adds support for Factory.ai's Droid CLI as a provider, enabling users to use Droid through an OpenAI-compatible API interface. Implementation details: - Created DroidApiService that wraps the droid CLI - Added DroidStrategy for protocol conversion (Claude-compatible) - Supports both streaming and non-streaming responses - No API keys or token management required - uses droid CLI directly Files added: - src/droid/droid-core.js: Core service using CLI wrapper - src/droid/droid-strategy.js: Strategy pattern implementation - src/droid/README.md: Comprehensive documentation - test-droid.js: Test script for validation Files modified: - src/adapter.js: Added DroidApiServiceAdapter - src/common.js: Added DROID constants - src/provider-strategies.js: Registered DroidStrategy - README.md: Updated with Droid provider information
5.1 KiB
5.1 KiB
Droid (Factory.ai) Provider
This adapter enables you to use Factory.ai's Droid CLI as an OpenAI-compatible API through AIClient2API.
Features
- ✅ Uses your existing Droid CLI installation
- ✅ No need for API keys or token management
- ✅ Full Claude API compatibility
- ✅ Supports streaming and non-streaming responses
- ✅ Works with any OpenAI-compatible client
Prerequisites
-
Install Droid CLI
# Install Droid CLI from Factory.ai # Visit: https://factory.ai/product/cli -
Authenticate with Droid
droid # Follow the prompts to login
Configuration
Using Command Line Arguments
node src/api-server.js \
--model-provider droid-factory-oauth \
--port 3000 \
--api-key your-api-key
Using config.json
Add to your config.json:
{
"MODEL_PROVIDER": "droid-factory-oauth",
"PORT": 3000,
"API_KEY": "your-api-key"
}
Using Environment Variables
export MODEL_PROVIDER=droid-factory-oauth
export PORT=3000
export API_KEY=your-api-key
node src/api-server.js
Usage
With OpenAI-Compatible Clients
Point your OpenAI-compatible client to the proxy:
import openai
client = openai.OpenAI(
base_url="http://localhost:3000/v1",
api_key="your-api-key"
)
response = client.chat.completions.create(
model="claude-sonnet-4-5-20250929",
messages=[
{"role": "user", "content": "Hello!"}
]
)
With Claude SDK
import anthropic
client = anthropic.Anthropic(
base_url="http://localhost:3000",
api_key="your-api-key" # Your proxy API key, not Anthropic's
)
message = client.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude!"}
]
)
With curl
# Claude API format
curl http://localhost:3000/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-5-20250929",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello!"}
]
}'
# OpenAI API format
curl http://localhost:3000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "claude-sonnet-4-5-20250929",
"messages": [
{"role": "user", "content": "Hello!"}
]
}'
Supported Models
The Droid provider supports all Claude models available through Factory.ai:
claude-sonnet-4-5-20250929(default)claude-3-7-sonnet-20250219claude-3-5-sonnet-20241022claude-3-opus-20240229
How It Works
The proxy converts OpenAI/Claude API requests into droid exec commands and streams the results back:
- Your app sends a request to the proxy (OpenAI or Claude format)
- The proxy converts messages to a prompt
- Executes
droid exec "your prompt" - Streams the response back in the requested format
Troubleshooting
"Droid CLI is not installed or not in PATH"
Problem: The droid command is not available
Solution:
- Install Droid CLI from https://factory.ai/product/cli
- Make sure
droidis in your system PATH - Test with:
droid --version
"Droid command failed"
Problem: Droid CLI returned an error
Solution:
- Make sure you are authenticated:
droid - Test droid directly:
droid exec "hello" - Check for any error messages from the droid CLI
Authentication Issues
Problem: Droid needs authentication
Solution:
- Run
droidto start an interactive session and authenticate - Follow the browser authentication flow
- After authentication, the proxy will work automatically
Architecture
Your App → AIClient2API Proxy → droid exec command → Factory.ai
(Port 3000) (CLI process)
The Droid provider:
- Receives API requests (OpenAI or Claude format)
- Converts messages to prompt text
- Spawns
droid exec "prompt"process - Streams output back to client
- Converts response to requested API format
Advanced Configuration
Custom Droid Command
If your droid CLI is installed with a different name or path:
{
"MODEL_PROVIDER": "droid-factory-oauth",
"DROID_COMMAND": "/custom/path/to/droid"
}
Security Considerations
- API key protection: Use strong API keys for the proxy itself
- Local execution: Droid CLI runs locally with your credentials
- Use HTTPS in production: Don't expose the proxy over HTTP in production
- Access control: Limit who can access your proxy server
Limitations
- Requires Droid CLI to be installed and authenticated
- Each request spawns a new
droid execprocess - Streaming support depends on droid CLI output behavior
- Authentication is managed by Droid CLI (not the proxy)
Contributing
When contributing Droid-related changes:
- Test with actual Droid CLI installation
- Ensure both streaming and non-streaming work
- Update this README with any new features
- Follow the existing code patterns in the project
License
This provider follows the same license as the main AIClient2API project (GPLv3).