Skip to content

Conversation

@CLEMENTINATOR
Copy link
Member

Summary

  • Add optional enable_compression: Option<bool> field to InputObject
  • Add optional compression_rate: Option<f64> field to InputObject
  • Add builder methods with_enable_compression() and with_compression_rate()
  • Include fields in request body for both send() and stream() methods
  • Fields are gateway-internal and not serialized to providers (using #[serde(default, skip_serializing)])

Test plan

  • Verify compression fields are included in request body when provided
  • Verify compression fields are omitted when not provided
  • Test builder methods work correctly
  • Test with both send() and stream() methods

🤖 Generated with Claude Code

@CLEMENTINATOR CLEMENTINATOR requested a review from a team as a code owner February 3, 2026 16:40
@SachaMorard
Copy link
Member

@CLEMENTINATOR Do you want to add the compression response field in another PR?

CLEMENTINATOR and others added 3 commits February 4, 2026 16:11
Add optional enable_compression and compression_rate fields to support
token compression configuration in the AI gateway.

- Add enable_compression (bool) and compression_rate (f64) to InputObject
- Add builder methods with_enable_compression() and with_compression_rate()
- Include fields in both send() and stream() request bodies
- Fields are gateway-internal and not serialized to providers

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Rename with_enable_compression to with_compression for better API consistency
- Add Compression struct with input_tokens, saved_tokens, and rate fields
- Add optional compression field to SendResponse for root-level compression data
- Add test for response with compression field deserialization
- Add test for response without compression field
- Add test for InputObject with_compression builder method
- Add example showing how to access compression data in responses
- Add compression info to features list
- Add example showing how to enable compression using builder pattern
- Demonstrate accessing compression metrics from response
- Show usage information alongside compression data
- Add substantial AI history document as context (~3000+ chars)
- Demonstrate meaningful compression on large input
- Show percentage of tokens saved
- Explain that compression works on input tokens
- Only USER messages are compressed, not system messages
- Update example to put context in user message
- Add clarifying comment about compression behavior
@CLEMENTINATOR CLEMENTINATOR merged commit d7157ea into main Feb 4, 2026
12 checks passed
@CLEMENTINATOR CLEMENTINATOR deleted the add-compression-fields branch February 4, 2026 15:42
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.

3 participants