modelmux 1.0.0

ModelMux - high-performance Rust gateway that translates OpenAI-compatible API requests to Vertex AI (Claude), with streaming, tool calling, and production-grade reliability.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
# ModelMux Implementation Plan
## Phased Roadmap with Actionable Steps

> **Strategy**: Focus on Vertex AI + Responses API excellence, add vLLM support for company needs, keep architecture open for future contributors.

---

## Phase 1: Foundation & Quick Wins (2-3 weeks)

**Goal**: Improve core quality, add vLLM support (for your company), ship Docker

### Week 1: Core Quality & Testing

#### Step 1.1: Add Comprehensive Tests (3-4 days)
- [ ] Create `tests/integration/` directory
- [ ] Add integration test for Vertex AI chat completions
  - [ ] Non-streaming request/response
  - [ ] Streaming request/response
  - [ ] Tool calling request/response
- [ ] Add integration test for health endpoint
- [ ] Add unit tests for converters
  - [ ] `OpenAI → Anthropic` message conversion
  - [ ] `Anthropic → OpenAI` message conversion
  - [ ] Tool/function conversion both ways
- [ ] Add error case tests
  - [ ] Invalid API keys
  - [ ] Malformed requests
  - [ ] Rate limiting scenarios
- [ ] Create test fixtures directory `tests/fixtures/`
  - [ ] Sample OpenAI requests
  - [ ] Sample Anthropic responses
  - [ ] Sample tool definitions
- [ ] Document how to run tests in README
  ```bash
  cargo test
  cargo test --features integration-tests
  ```

#### Step 1.2: Improve Error Handling (2-3 days)
- [ ] Audit all error types in `src/error.rs`
- [ ] Add specific error variants for:
  - [ ] `ConfigurationError` (missing fields, invalid values)
  - [ ] `AuthenticationError` (GCP auth issues)
  - [ ] `ProviderError` (upstream API errors)
  - [ ] `ConversionError` (format translation issues)
- [ ] Improve error messages with actionable suggestions
  ```rust
  ConfigurationError::MissingProject => 
    "Missing VERTEX_PROJECT. Run: modelmux config init"
  ```
- [ ] Add error context preservation
  ```rust
  .context("Failed to convert OpenAI request to Anthropic format")?
  ```
- [ ] Add request ID tracking for debugging
- [ ] Log errors with structured data (JSON format)

#### Step 1.3: Documentation Pass (1-2 days)
- [ ] Create `docs/API_COMPATIBILITY.md`
  - [ ] List supported OpenAI endpoints
  - [ ] List supported features (streaming, tools, etc.)
  - [ ] List known limitations
  - [ ] List model mappings
- [ ] Create `docs/TROUBLESHOOTING.md`
  - [ ] Common errors and solutions
  - [ ] Debug mode instructions
  - [ ] Log interpretation guide
- [ ] Update README with examples
  - [ ] cURL examples for common use cases
  - [ ] SDK examples (Python, TypeScript)
  - [ ] Environment variable reference

### Week 2: vLLM Support (Company Priority)

#### Step 2.1: Implement OpenAI-Compatible Provider (3-4 days)
- [ ] Create `src/provider/openai_compatible.rs`
  ```rust
  pub struct OpenAiCompatibleProvider {
      client: reqwest::Client,
      base_url: String,
      api_key: String,
      model: String,
  }
  ```
- [ ] Implement `LlmProvider` trait
  - [ ] `chat_completions()` method
  - [ ] `chat_completions_stream()` method
  - [ ] Error handling with proper conversion
- [ ] Add authentication
  - [ ] Bearer token in Authorization header
  - [ ] Support API key in custom header (some vLLM setups)
- [ ] Add request forwarding
  - [ ] Pass OpenAI format directly (no conversion needed!)
  - [ ] Handle streaming responses
  - [ ] Preserve headers and error codes
- [ ] Add timeout configuration
- [ ] Add retry logic (reuse existing code)

#### Step 2.2: Add Provider Configuration (1-2 days)
- [ ] Extend `config.toml` schema
  ```toml
  [provider]
  type = "vertex"  # or "openai_compatible"
  
  # For OpenAI-compatible providers (vLLM, etc.)
  [provider.openai_compatible]
  base_url = "http://localhost:8000/v1"
  api_key = "${VLLM_API_KEY}"  # or "none" for local
  model = "meta-llama/Llama-3-8B-Instruct"
  timeout_seconds = 120
  ```
- [ ] Update `src/config.rs` to parse provider config
- [ ] Add provider factory pattern
  ```rust
  pub enum ProviderType {
      Vertex,
      OpenAiCompatible,
  }
  
  pub fn create_provider(config: &Config) -> Result<Box<dyn LlmProvider>> {
      match config.provider.type {
          ProviderType::Vertex => Ok(Box::new(VertexProvider::new(config)?)),
          ProviderType::OpenAiCompatible => Ok(Box::new(OpenAiCompatibleProvider::new(config)?)),
      }
  }
  ```
- [ ] Add validation for provider-specific config
- [ ] Update `modelmux config init` to ask about provider type

#### Step 2.3: Test vLLM Integration (1-2 days)
- [ ] Create test script for local vLLM
  ```bash
  # Start vLLM server
  python -m vllm.entrypoints.openai.api_server \
    --model meta-llama/Llama-3-8B-Instruct \
    --port 8000
  
  # Configure ModelMux
  modelmux config init --preset vllm
  
  # Test
  curl http://localhost:3000/v1/chat/completions ...
  ```
- [ ] Document vLLM setup in `docs/VLLM_SETUP.md`
- [ ] Add example config for gpt-oss-120b
- [ ] Test failover scenario (Vertex → vLLM)
- [ ] Document known vLLM quirks/limitations

### Week 3: Docker & Deployment

#### Step 3.1: Docker Image (2-3 days)
- [ ] Create multi-stage `Dockerfile`
  ```dockerfile
  # Builder stage
  FROM rust:1.84-slim as builder
  WORKDIR /app
  COPY . .
  RUN cargo build --release
  
  # Runtime stage
  FROM debian:bookworm-slim
  RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
  COPY --from=builder /app/target/release/modelmux /usr/local/bin/
  EXPOSE 3000
  CMD ["modelmux"]
  ```
- [ ] Test multi-arch builds (amd64, arm64)
  ```bash
  docker buildx build --platform linux/amd64,linux/arm64 -t modelmux:latest .
  ```
- [ ] Create `.dockerignore`
- [ ] Optimize image size (use Alpine? scratch?)
- [ ] Add health check
  ```dockerfile
  HEALTHCHECK --interval=30s --timeout=3s \
    CMD curl -f http://localhost:3000/health || exit 1
  ```

#### Step 3.2: Docker Compose Examples (1 day)
- [ ] Create `docker-compose.yml` for Vertex AI
  ```yaml
  services:
    modelmux:
      image: modelmux:latest
      ports:
        - "3000:3000"
      volumes:
        - ./config:/config
        - ./service-account.json:/secrets/sa.json
      environment:
        - MODELMUX_CONFIG_FILE=/config/config.toml
  ```
- [ ] Create `docker-compose.vllm.yml` for vLLM + ModelMux
  ```yaml
  services:
    vllm:
      image: vllm/vllm-openai:latest
      ports:
        - "8000:8000"
      command: --model meta-llama/Llama-3-8B-Instruct
      
    modelmux:
      image: modelmux:latest
      ports:
        - "3000:3000"
      environment:
        - PROVIDER_TYPE=openai_compatible
        - OPENAI_BASE_URL=http://vllm:8000/v1
  ```
- [ ] Document Docker deployment in README
- [ ] Add Kubernetes example (optional)

#### Step 3.3: Binary Releases (1 day)
- [ ] Set up GitHub Actions for releases
- [ ] Build for multiple targets
  - [ ] `x86_64-unknown-linux-gnu`
  - [ ] `aarch64-unknown-linux-gnu`
  - [ ] `x86_64-apple-darwin`
  - [ ] `aarch64-apple-darwin`
- [ ] Create release workflow
  ```yaml
  # .github/workflows/release.yml
  on:
    push:
      tags:
        - 'v*'
  jobs:
    build:
      # ... build for each platform
      # ... create GitHub release
      # ... upload artifacts
  ```
- [ ] Update Homebrew formula automatically

---

## Phase 2: Responses API Foundation (3-4 weeks)

**Goal**: Research, design, and implement core Responses API support

### Week 4: Research & Design

#### Step 4.1: Responses API Deep Dive (2-3 days)
- [ ] Study OpenAI Responses API documentation
  - [ ] Request format (`input`, `instructions`, `modalities`)
  - [ ] Response format (`output`, `usage`, `metadata`)
  - [ ] State management (`previous_response_id`, `store`)
  - [ ] Built-in tools (`web_search`, `file_search`, etc.)
  - [ ] Structured outputs (`text.format`)
- [ ] Compare with Chat Completions API
  - [ ] Create mapping table (see below)
  - [ ] Identify translation challenges
  - [ ] Document unsupported features
- [ ] Study vLLM's Responses API implementation
  - [ ] What they support
  - [ ] What they don't support
- [ ] Create `docs/RESPONSES_API_DESIGN.md`

#### Step 4.2: Design Translation Layer (2-3 days)
- [ ] Design data structures
  ```rust
  // src/types/responses_api.rs
  pub struct ResponsesRequest {
      pub input: InputContent,
      pub instructions: Option<String>,
      pub previous_response_id: Option<String>,
      pub modalities: Vec<String>,
      pub tools: Vec<Tool>,
      pub store: Option<bool>,
      // ...
  }
  
  pub struct ResponsesResponse {
      pub id: String,
      pub output: Vec<OutputItem>,
      pub usage: Usage,
      pub metadata: Metadata,
      // ...
  }
  ```
- [ ] Design conversion strategy
  ```
  Responses Request → Chat Completions Request:
  - input (string/items) → messages (with system role for instructions)
  - previous_response_id → inject previous messages into context
  - modalities → infer from content types
  - tools → convert format
  
  Chat Completions Response → Responses Response:
  - choices[0].message → output items
  - Handle tool calls → output items with type="function_call"
  - Generate response ID
  - Metadata transformation
  ```
- [ ] Identify edge cases
  - [ ] Multimodal input handling
  - [ ] State persistence (where to store `previous_response_id` data?)
  - [ ] Tool result correlation
- [ ] Decide on state storage approach
  - [ ] Option 1: In-memory cache (simple, loses state on restart)
  - [ ] Option 2: Redis (persistent, scales)
  - [ ] Option 3: File-based (simple persistence)
  - [ ] **Recommendation**: Start with in-memory, add Redis later

#### Step 4.3: API Compatibility Matrix (1 day)
- [ ] Create comprehensive comparison document
  - [ ] Feature-by-feature breakdown
  - [ ] What works with Vertex
  - [ ] What works with vLLM
  - [ ] What requires translation
  - [ ] What's not possible
- [ ] Document in `docs/RESPONSES_API_SUPPORT.md`

### Week 5-6: Core Implementation

#### Step 5.1: Data Types & Parsing (3-4 days)
- [ ] Create `src/types/responses_api.rs`
- [ ] Implement all Responses API types
  ```rust
  pub struct ResponsesRequest { /* ... */ }
  pub struct ResponsesResponse { /* ... */ }
  pub struct InputContent { /* ... */ }
  pub struct OutputItem { /* ... */ }
  pub struct Metadata { /* ... */ }
  ```
- [ ] Add Serde serialization/deserialization
- [ ] Add validation
  ```rust
  impl ResponsesRequest {
      pub fn validate(&self) -> Result<()> {
          // Validate required fields
          // Validate modalities
          // Validate tool schemas
          // ...
      }
  }
  ```
- [ ] Add tests for parsing

#### Step 5.2: Request Converter (3-4 days)
- [ ] Create `src/converter/responses_to_chat.rs`
  ```rust
  pub struct ResponsesToChatConverter;
  
  impl ResponsesToChatConverter {
      pub fn convert_request(
          req: ResponsesRequest,
          context: Option<ConversionContext>,
      ) -> Result<ChatCompletionRequest> {
          // Implementation
      }
  }
  ```
- [ ] Implement input → messages conversion
  - [ ] String input → single user message
  - [ ] Array input → multiple messages
  - [ ] Instructions → system message
- [ ] Implement tool conversion
  - [ ] Responses tool format → Chat Completions function format
  - [ ] Handle built-in tools (mark as unsupported for now)
- [ ] Implement state injection
  - [ ] Load previous conversation from `previous_response_id`
  - [ ] Inject into messages array
- [ ] Add comprehensive tests

#### Step 5.3: Response Converter (3-4 days)
- [ ] Create `src/converter/chat_to_responses.rs`
  ```rust
  pub struct ChatToResponsesConverter;
  
  impl ChatToResponsesConverter {
      pub fn convert_response(
          res: ChatCompletionResponse,
          metadata: ResponseMetadata,
      ) -> Result<ResponsesResponse> {
          // Implementation
      }
  }
  ```
- [ ] Implement message → output conversion
  - [ ] Text content → text output item
  - [ ] Tool calls → function_call output items
  - [ ] Handle multiple choice scenarios
- [ ] Generate response IDs
  ```rust
  fn generate_response_id() -> String {
      format!("resp_{}", uuid::Uuid::new_v4())
  }
  ```
- [ ] Add metadata transformation
- [ ] Add comprehensive tests

### Week 7: API Endpoint & State Management

#### Step 7.1: State Storage (2-3 days)
- [ ] Create `src/state/mod.rs`
  ```rust
  #[async_trait]
  pub trait StateStore: Send + Sync {
      async fn save_conversation(
          &self,
          response_id: &str,
          data: ConversationState,
      ) -> Result<()>;
      
      async fn load_conversation(
          &self,
          response_id: &str,
      ) -> Result<Option<ConversationState>>;
      
      async fn delete_conversation(&self, response_id: &str) -> Result<()>;
  }
  ```
- [ ] Implement in-memory store
  ```rust
  pub struct InMemoryStateStore {
      store: Arc<RwLock<HashMap<String, ConversationState>>>,
  }
  ```
- [ ] Add TTL for stored conversations
- [ ] Add size limits (prevent memory leak)
- [ ] Add cleanup task (delete expired conversations)

#### Step 7.2: Responses Endpoint (2-3 days)
- [ ] Add route in `src/server.rs`
  ```rust
  async fn handle_responses_request(
      State(state): State<AppState>,
      Json(req): Json<ResponsesRequest>,
  ) -> Result<Json<ResponsesResponse>> {
      // Validate request
      req.validate()?;
      
      // Convert to Chat Completions format
      let chat_req = converter.convert_request(req, context)?;
      
      // Call provider
      let chat_res = provider.chat_completions(chat_req).await?;
      
      // Convert back to Responses format
      let responses_res = converter.convert_response(chat_res, metadata)?;
      
      // Store conversation state if requested
      if req.store == Some(true) {
          state_store.save_conversation(&responses_res.id, state).await?;
      }
      
      Ok(Json(responses_res))
  }
  ```
- [ ] Add streaming variant
  ```rust
  async fn handle_responses_request_stream(
      State(state): State<AppState>,
      Json(req): Json<ResponsesRequest>,
  ) -> Sse<impl Stream<Item = Result<Event>>> {
      // Similar to above but streaming
  }
  ```
- [ ] Wire up to router
  ```rust
  Router::new()
      .route("/v1/responses", post(handle_responses_request))
      // ...
  ```

#### Step 7.3: Integration Testing (2 days)
- [ ] Create `tests/integration/responses_api.rs`
- [ ] Test basic request/response
- [ ] Test with previous_response_id
- [ ] Test with tools
- [ ] Test streaming
- [ ] Test error cases
- [ ] Document usage examples

---

## Phase 3: Advanced Features & Polish (3-4 weeks)

**Goal**: Production-ready observability, optimizations, and user experience

### Week 8: Observability

#### Step 8.1: Prometheus Metrics (2-3 days)
- [ ] Add `prometheus` crate dependency
- [ ] Create metrics registry in `src/metrics.rs`
  ```rust
  use prometheus::{
      register_counter_vec, register_histogram_vec, CounterVec, HistogramVec,
  };
  
  lazy_static! {
      pub static ref HTTP_REQUESTS_TOTAL: CounterVec = register_counter_vec!(
          "modelmux_http_requests_total",
          "Total HTTP requests",
          &["method", "endpoint", "status"]
      ).unwrap();
      
      pub static ref REQUEST_DURATION: HistogramVec = register_histogram_vec!(
          "modelmux_request_duration_seconds",
          "Request duration in seconds",
          &["endpoint", "provider"]
      ).unwrap();
      
      pub static ref PROVIDER_REQUESTS: CounterVec = register_counter_vec!(
          "modelmux_provider_requests_total",
          "Total provider requests",
          &["provider", "model", "status"]
      ).unwrap();
      
      pub static ref TOKEN_USAGE: CounterVec = register_counter_vec!(
          "modelmux_tokens_total",
          "Total tokens processed",
          &["provider", "model", "type"]  // type: input/output
      ).unwrap();
  }
  ```
- [ ] Add metrics middleware
  ```rust
  pub async fn metrics_middleware(
      req: Request,
      next: Next,
  ) -> Response {
      let start = Instant::now();
      let method = req.method().to_string();
      let path = req.uri().path().to_string();
      
      let response = next.run(req).await;
      
      let duration = start.elapsed().as_secs_f64();
      let status = response.status().as_u16().to_string();
      
      HTTP_REQUESTS_TOTAL
          .with_label_values(&[&method, &path, &status])
          .inc();
      
      REQUEST_DURATION
          .with_label_values(&[&path, "vertex"])
          .observe(duration);
      
      response
  }
  ```
- [ ] Add `/metrics` endpoint
  ```rust
  async fn metrics_handler() -> Response {
      use prometheus::Encoder;
      let encoder = prometheus::TextEncoder::new();
      let metrics = prometheus::gather();
      let mut buffer = Vec::new();
      encoder.encode(&metrics, &mut buffer).unwrap();
      Response::builder()
          .header("Content-Type", encoder.format_type())
          .body(buffer.into())
          .unwrap()
  }
  ```
- [ ] Instrument all key paths
  - [ ] HTTP requests
  - [ ] Provider calls
  - [ ] Token usage
  - [ ] Errors by type
  - [ ] Cache hits/misses (when caching added)

#### Step 8.2: Structured Logging (1-2 days)
- [ ] Switch to structured logging with `tracing`
- [ ] Add request ID to all logs
  ```rust
  #[instrument(skip_all, fields(request_id = %uuid::Uuid::new_v4()))]
  async fn handle_chat_completion(req: Request) -> Response {
      tracing::info!("Processing chat completion request");
      // ...
  }
  ```
- [ ] Log key events
  - [ ] Request received (with sanitized payload)
  - [ ] Provider call started
  - [ ] Provider call completed (with latency)
  - [ ] Response sent
  - [ ] Errors (with full context)
- [ ] Add log levels appropriately
  - [ ] DEBUG: Detailed request/response data
  - [ ] INFO: Key operations
  - [ ] WARN: Retries, fallbacks
  - [ ] ERROR: Failures
- [ ] Support JSON output format
  ```toml
  [server]
  log_format = "json"  # or "pretty"
  ```

#### Step 8.3: Health Checks Enhanced (1 day)
- [ ] Extend `/health` endpoint
  ```json
  {
    "status": "healthy",
    "version": "0.7.0",
    "uptime_seconds": 3600,
    "provider": {
      "type": "vertex",
      "healthy": true,
      "last_check": "2025-02-15T10:00:00Z"
    },
    "metrics": {
      "total_requests": 1000,
      "success_rate": 0.98,
      "avg_latency_ms": 245
    }
  }
  ```
- [ ] Add liveness probe `/health/live`
- [ ] Add readiness probe `/health/ready`
  - [ ] Check provider connectivity
  - [ ] Check state store connectivity
- [ ] Add configurable health check interval

### Week 9: Performance & Caching

#### Step 9.1: Request Caching (3-4 days)
- [ ] Add `redis` crate (or `moka` for in-memory)
- [ ] Create `src/cache/mod.rs`
  ```rust
  #[async_trait]
  pub trait Cache: Send + Sync {
      async fn get(&self, key: &str) -> Result<Option<Vec<u8>>>;
      async fn set(&self, key: &str, value: Vec<u8>, ttl: Duration) -> Result<()>;
      async fn delete(&self, key: &str) -> Result<()>;
  }
  ```
- [ ] Implement Redis cache
  ```rust
  pub struct RedisCache {
      client: redis::Client,
  }
  ```
- [ ] Implement in-memory cache (for development)
  ```rust
  pub struct InMemoryCache {
      cache: moka::future::Cache<String, Vec<u8>>,
  }
  ```
- [ ] Add cache key generation
  ```rust
  fn generate_cache_key(req: &ChatCompletionRequest) -> String {
      use std::collections::hash_map::DefaultHasher;
      use std::hash::{Hash, Hasher};
      
      let mut hasher = DefaultHasher::new();
      req.messages.hash(&mut hasher);
      req.model.hash(&mut hasher);
      // Include relevant fields but not temperature, etc.
      format!("chat:{:x}", hasher.finish())
  }
  ```
- [ ] Add cache middleware
  ```rust
  async fn cache_middleware(
      State(cache): State<Arc<dyn Cache>>,
      req: Request,
      next: Next,
  ) -> Response {
      // Check cache
      if let Some(cached) = cache.get(&key).await.ok().flatten() {
          CACHE_HITS.inc();
          return Response::from_bytes(cached);
      }
      
      // Process request
      let response = next.run(req).await;
      
      // Store in cache
      cache.set(&key, response.bytes(), TTL).await.ok();
      CACHE_MISSES.inc();
      
      response
  }
  ```
- [ ] Add cache configuration
  ```toml
  [cache]
  enabled = true
  type = "redis"  # or "memory"
  redis_url = "redis://localhost:6379"
  ttl_seconds = 3600
  max_size_mb = 100
  ```
- [ ] Add cache metrics (hits, misses, evictions)

#### Step 9.2: Connection Pooling (1-2 days)
- [ ] Review `reqwest::Client` configuration
- [ ] Optimize connection pool settings
  ```rust
  let client = reqwest::Client::builder()
      .pool_max_idle_per_host(10)
      .pool_idle_timeout(Duration::from_secs(90))
      .timeout(Duration::from_secs(120))
      .build()?;
  ```
- [ ] Add connection pool metrics
- [ ] Test under load (use `wrk` or `hey`)

#### Step 9.3: Performance Testing (1-2 days)
- [ ] Create load test scripts
  ```bash
  # tests/load/basic_chat.lua (for wrk)
  wrk -t 4 -c 100 -d 30s -s basic_chat.lua http://localhost:3000
  ```
- [ ] Test scenarios
  - [ ] Simple chat completions
  - [ ] Streaming responses
  - [ ] Tool calling
  - [ ] With caching enabled/disabled
- [ ] Document performance benchmarks
- [ ] Identify bottlenecks
- [ ] Optimize hot paths

### Week 10: Configuration & UX

#### Step 10.1: Configuration Presets (2-3 days)
- [ ] Create preset templates
  - [ ] `presets/vertex.toml`
  - [ ] `presets/vllm.toml`
  - [ ] `presets/azure.toml`
- [ ] Enhance `modelmux config init`
  ```rust
  // Ask user which provider
  let provider = Select::new()
      .with_prompt("Which provider?")
      .items(&["Vertex AI", "vLLM (local)", "Azure OpenAI"])
      .interact()?;
  
  // Load appropriate preset
  let preset = load_preset(provider)?;
  
  // Ask for required values
  let config = customize_preset(preset)?;
  
  // Write config
  write_config(&config)?;
  ```
- [ ] Add preset validation
- [ ] Document presets in README

#### Step 10.2: Better Error Messages (1-2 days)
- [ ] Audit all error messages
- [ ] Add actionable suggestions
  ```
  Error: Authentication failed
  
  Possible causes:
  1. Service account file not found
     → Run: modelmux config init
  2. Invalid credentials
     → Check: /path/to/service-account.json
  3. Insufficient permissions
     → Required: roles/aiplatform.user
  
  For more help: modelmux troubleshoot auth
  ```
- [ ] Add `modelmux troubleshoot` command
- [ ] Add common error solutions to docs

#### Step 10.3: Environment Auto-Detection (1 day)
- [ ] Detect GCP environment
  ```rust
  fn detect_gcp_environment() -> Option<GcpEnv> {
      // Check GOOGLE_APPLICATION_CREDENTIALS
      // Check default credentials path
      // Check GCE metadata server
      // Check gcloud config
  }
  ```
- [ ] Auto-discover Vertex AI settings
  ```rust
  fn discover_vertex_config() -> Option<VertexConfig> {
      // Get project from gcloud config
      // Get region from environment
      // Suggest available models
  }
  ```
- [ ] Make `modelmux config init` smarter with defaults

### Week 11: Documentation & Examples

#### Step 11.1: Comprehensive Documentation (3-4 days)
- [ ] Create `docs/` directory structure
  ```
  docs/
  ├── getting-started/
  │   ├── installation.md
  │   ├── quickstart.md
  │   └── configuration.md
  ├── guides/
  │   ├── vertex-ai-setup.md
  │   ├── vllm-setup.md
  │   ├── docker-deployment.md
  │   └── kubernetes-deployment.md
  ├── api/
  │   ├── chat-completions.md
  │   ├── responses-api.md
  │   └── compatibility.md
  ├── observability/
  │   ├── metrics.md
  │   ├── logging.md
  │   └── tracing.md
  └── troubleshooting/
      ├── common-errors.md
      └── debugging.md
  ```
- [ ] Write each guide with examples
- [ ] Add diagrams (architecture, flow)
- [ ] Add screenshots where helpful

#### Step 11.2: Code Examples (2-3 days)
- [ ] Create `examples/` directory
  ```
  examples/
  ├── python/
  │   ├── basic_chat.py
  │   ├── streaming.py
  │   ├── tool_calling.py
  │   └── responses_api.py
  ├── typescript/
  │   ├── basic_chat.ts
  │   ├── streaming.ts
  │   └── tool_calling.ts
  ├── rust/
  │   └── client_example.rs
  └── curl/
      └── examples.sh
  ```
- [ ] Test all examples
- [ ] Document in README

#### Step 11.3: Video/Blog Content (1-2 days)
- [ ] Create demo video
  - [ ] Installation
  - [ ] Configuration
  - [ ] First request
  - [ ] Docker deployment
- [ ] Write blog post
  - [ ] "Building an OpenAI-Compatible Proxy in Rust"
  - [ ] "Migrating from OpenAI to Vertex AI"
  - [ ] "Supporting Multiple LLM Providers"
- [ ] Share on Reddit, HN, etc.

---

## Phase 4: Community & Extensibility (Ongoing)

**Goal**: Make it easy for contributors to add features

### Step 12.1: Contributor Guidelines (1-2 days)
- [ ] Create `CONTRIBUTING.md`
  - [ ] How to set up dev environment
  - [ ] How to run tests
  - [ ] Code style guide
  - [ ] How to add a new provider
  - [ ] How to add a new endpoint
- [ ] Create `docs/ARCHITECTURE.md`
  - [ ] High-level design
  - [ ] Key abstractions
  - [ ] Extension points
- [ ] Create issue templates
  - [ ] Bug report
  - [ ] Feature request
  - [ ] Provider support request

### Step 12.2: Provider Plugin System (Optional, 1-2 weeks)
- [ ] Design plugin architecture
  ```rust
  // Allow external crates to implement LlmProvider
  // Load plugins from config
  [provider]
  type = "plugin"
  plugin_path = "./target/release/libmy_provider.so"
  ```
- [ ] Implement dynamic loading
- [ ] Document plugin development
- [ ] Create example plugin

### Step 12.3: Community Features (Ongoing)
- [ ] Set up Discord/Slack community
- [ ] Create roadmap voting system
- [ ] Regular releases (semantic versioning)
- [ ] Changelog maintenance

---

## Priority Quick Reference

### Week 1
✅ Tests, error handling, docs

### Week 2
🚀 vLLM support (company priority)

### Week 3
🐳 Docker, deployment

### Week 4
📖 Responses API research & design

### Week 5-7
🔧 Responses API implementation

### Week 8
📊 Observability (metrics, logging)

### Week 9
⚡ Performance (caching, optimization)

### Week 10
🎨 UX (presets, error messages)

### Week 11
📚 Documentation & examples

---

## Success Metrics

After Phase 1 (3 weeks):
- [ ] vLLM works for company use case
- [ ] Docker image available
- [ ] Integration tests pass

After Phase 2 (6 weeks):
- [ ] Responses API works with Vertex AI
- [ ] State management functional
- [ ] Basic examples working

After Phase 3 (10 weeks):
- [ ] Production-ready observability
- [ ] Performance optimized
- [ ] Comprehensive documentation

---

## Notes for Contributors

If others want to contribute, these are **high-value, self-contained tasks**:

1. **AWS Bedrock provider** (similar to vLLM, but AWS auth)
2. **Azure OpenAI provider** (easiest - just URL + auth)
3. **Embeddings endpoint** (`/v1/embeddings`)
4. **Built-in tools** (web_search, file_search)
5. **Web UI** (config management, monitoring)
6. **Terraform/CloudFormation** (deployment templates)
7. **Helm chart** (Kubernetes deployment)

Each can be developed independently without blocking core work.

---

## Timeline Summary

| Phase | Duration | End Result |
|-------|----------|------------|
| Phase 1: Foundation | 3 weeks | vLLM working, Docker ready, tests passing |
| Phase 2: Responses API | 4 weeks | Responses API functional with Vertex |
| Phase 3: Polish | 4 weeks | Production-ready, well-documented |
| **Total** | **~11 weeks** | **Professional, extensible proxy** |

---

## Next Actions (Start Tomorrow)

1. Create `tests/integration/` directory — **[TASK-001]tasks/TASK-001-integration-tests.md**
2. Write first integration test — **TASK-001**
3. Implement `OpenAiCompatibleProvider`**[TASK-004]tasks/TASK-004-openai-compatible-provider.md**
4. Update config schema for provider selection — **[TASK-005]tasks/TASK-005-provider-configuration.md**

**Task index**: See [tasks/README.md](tasks/README.md) for all detailed task files. Each task follows [AGENT.md](AGENT.md) and [tools/task_template.md](tools/task_template.md).

Let's build! 🚀