lex-claude 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d2e4536ac507b72ebd29355fe866027db4b54c226ab9c3134e9e21b73c68b93
4
- data.tar.gz: 798a964602097b7959364befe12d6e7485c18631c3bb2192b3f25f7f066a0233
3
+ metadata.gz: 0b422c38d51391b457e88f4760b941afe22a835be9ba5405812a89024e082bb4
4
+ data.tar.gz: 23c95a1d66de519a7f24d9bdf86d522d13cc53b47732bdce3709dcee09df20bd
5
5
  SHA512:
6
- metadata.gz: ea03fb131e3d69af3ca1318b5f4a5d5e41b478d17a20596b5e4440e3f4d009d7f4f0af72bae2709130c4054feb0014dca0c07e4c64751185321fad0ea4d203ac
7
- data.tar.gz: 449da0ea883f5abc4ee9ff1175552f361781f0fea197c86de945a33424ed66c6d0f0d3fb962d2b4318a22a9a216e0ffa5855a27434d21d7625d54e266ce0adeb
6
+ metadata.gz: aa72850dab4628a3fcf6e6f6bd479ec5e3d4c9518710f05ab28f695c3f4b6834bb3615fbb79630b111d66317b13938a0145f281b93b6e0edab3a2e3e91f48c14
7
+ data.tar.gz: a0a9cff50d0bbd456f5eb2fd0270132721ddfad15d60d140aa63277bbb80a604c27aafb1e56ddacfdd89e85d573aec8dc755fa58a8f7fcb907f672f543eb5cec
@@ -0,0 +1,7 @@
1
+ # Auto-generated from team-config.yml
2
+ # Team: ai
3
+ #
4
+ # To apply: scripts/apply-codeowners.sh lex-claude
5
+
6
+ * @LegionIO/maintainers
7
+ * @LegionIO/ai
@@ -0,0 +1,18 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: /
5
+ schedule:
6
+ interval: weekly
7
+ day: monday
8
+ open-pull-requests-limit: 5
9
+ labels:
10
+ - "type:dependencies"
11
+ - package-ecosystem: github-actions
12
+ directory: /
13
+ schedule:
14
+ interval: weekly
15
+ day: monday
16
+ open-pull-requests-limit: 5
17
+ labels:
18
+ - "type:dependencies"
@@ -3,13 +3,31 @@ on:
3
3
  push:
4
4
  branches: [main]
5
5
  pull_request:
6
+ schedule:
7
+ - cron: '0 9 * * 1'
6
8
 
7
9
  jobs:
8
10
  ci:
9
11
  uses: LegionIO/.github/.github/workflows/ci.yml@main
10
12
 
13
+ excluded-files:
14
+ uses: LegionIO/.github/.github/workflows/excluded-files.yml@main
15
+
16
+ security:
17
+ uses: LegionIO/.github/.github/workflows/security-scan.yml@main
18
+
19
+ version-changelog:
20
+ uses: LegionIO/.github/.github/workflows/version-changelog.yml@main
21
+
22
+ dependency-review:
23
+ uses: LegionIO/.github/.github/workflows/dependency-review.yml@main
24
+
25
+ stale:
26
+ if: github.event_name == 'schedule'
27
+ uses: LegionIO/.github/.github/workflows/stale.yml@main
28
+
11
29
  release:
12
- needs: ci
30
+ needs: [ci, excluded-files]
13
31
  if: github.event_name == 'push' && github.ref == 'refs/heads/main'
14
32
  uses: LegionIO/.github/.github/workflows/release.yml@main
15
33
  secrets:
data/.rubocop.yml CHANGED
@@ -1,50 +1,2 @@
1
- AllCops:
2
- TargetRubyVersion: 3.4
3
- NewCops: enable
4
- SuggestExtensions: false
5
-
6
- Layout/LineLength:
7
- Max: 160
8
-
9
- Layout/SpaceAroundEqualsInParameterDefault:
10
- EnforcedStyle: space
11
-
12
- Layout/HashAlignment:
13
- EnforcedHashRocketStyle: table
14
- EnforcedColonStyle: table
15
-
16
- Metrics/MethodLength:
17
- Max: 50
18
-
19
- Metrics/ClassLength:
20
- Max: 1500
21
-
22
- Metrics/ModuleLength:
23
- Max: 1500
24
-
25
- Metrics/BlockLength:
26
- Max: 40
27
- Exclude:
28
- - 'spec/**/*'
29
-
30
- Metrics/AbcSize:
31
- Max: 60
32
-
33
- Metrics/CyclomaticComplexity:
34
- Max: 15
35
-
36
- Metrics/PerceivedComplexity:
37
- Max: 17
38
-
39
- Style/Documentation:
40
- Enabled: false
41
-
42
- Style/SymbolArray:
43
- Enabled: true
44
-
45
- Style/FrozenStringLiteralComment:
46
- Enabled: true
47
- EnforcedStyle: always
48
-
49
- Naming/FileName:
50
- Enabled: false
1
+ inherit_gem:
2
+ rubocop-legion: config/lex.yml
data/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.0] - 2026-03-31
4
+
5
+ ### Added
6
+ - `Helpers::Errors` — structured exception hierarchy (`ApiError`, `RateLimitError`, `OverloadedError`, `AuthenticationError`, `PermissionError`, `NotFoundError`, `InvalidRequestError`, `ServerError`, `StreamingError`); `from_response` factory; `retryable?` predicate
7
+ - `Helpers::Retry` — exponential backoff retry wrapper (`with_retry`) with configurable `max_attempts`, `base_delay`, `max_delay`
8
+ - `Helpers::Sse` — SSE event stream parser (`parse_stream`), text assembler (`collect_text`), usage merger (`collect_usage`)
9
+ - `Helpers::Response` — `handle_response` raises typed exceptions on non-2xx, parses 9 Anthropic rate limit headers, `parse_usage` extracts standard + cache token counts
10
+ - `Helpers::Client::BETA_HEADERS` — registry of 18 named beta identifiers; `client` factory accepts `betas:` array
11
+ - `Helpers::Client.streaming_client` — Faraday connection for SSE responses
12
+ - `Helpers::Tools` — `web_search` factory, `cache_control` helper, `required_betas_for` inspector
13
+ - `Helpers::Models` — registry of 11 canonical Claude model IDs with Symbol alias resolution; `adaptive_thinking?` predicate
14
+ - `Runners::Messages#create_stream` — streaming message creation with SSE event yielding
15
+ - `cache_system:` wraps system prompt in ephemeral cache_control block
16
+ - `cache_scope: :global` auto-injects `prompt-caching-scope-2026-01-05` beta
17
+ - `thinking:` for extended thinking with temperature auto-omission and beta auto-injection
18
+ - `output_config:` for structured output (JSON schema), effort control, task budgets with auto-beta
19
+ - `fast_mode: true` sends `speed: 'fast'` with `fast-mode-2026-02-01` beta
20
+ - `context_management:` with `context-management-2025-06-27` beta auto-injection
21
+ - `:usage` key in all `create` results with `input_tokens`, `output_tokens`, `cache_read_tokens`, `cache_write_tokens`
22
+ - All new helpers wired into main `require 'legion/extensions/claude'` tree
23
+ - Updated README with comprehensive examples for all new features
24
+
25
+ ### Changed
26
+ - All runners raise typed `Helpers::Errors::*` exceptions instead of returning raw status codes
27
+ - `Messages#create` and `#create_stream` refactored to use shared `build_message_body` and `resolve_feature_betas` helpers
28
+ - `Messages#count_tokens` now accepts `thinking:`, `cache_system:` keywords
29
+ - Added `rubocop-legion` for consistent linting
30
+
31
+ ## [0.1.3] - 2026-03-30
32
+
33
+ ### Changed
34
+ - update to rubocop-legion 0.1.7, resolve all offenses
35
+
3
36
  ## [0.1.2] - 2026-03-22
4
37
 
5
38
  ### Changed
data/CLAUDE.md CHANGED
@@ -10,7 +10,7 @@ Legion Extension that connects LegionIO to the Claude Anthropic API. Provides ru
10
10
 
11
11
  **GitHub**: https://github.com/LegionIO/lex-claude
12
12
  **License**: MIT
13
- **Version**: 0.1.1
13
+ **Version**: 0.1.2
14
14
  **Specs**: 18 examples
15
15
 
16
16
  ## Architecture
data/Gemfile CHANGED
@@ -8,5 +8,6 @@ group :test do
8
8
  gem 'rspec'
9
9
  gem 'rspec_junit_formatter'
10
10
  gem 'rubocop'
11
+ gem 'rubocop-legion', '~> 0.1'
11
12
  gem 'simplecov'
12
13
  end
data/LICENSE CHANGED
@@ -1,21 +1,201 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2026 Esity
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021 Esity
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # lex-claude
2
2
 
3
- Claude Anthropic API integration for LegionIO. Provides runners for creating messages, listing models, counting tokens, and managing message batches.
3
+ Production-grade Claude Anthropic API integration for LegionIO. Provides runners for creating messages (streaming and batch), counting tokens, listing models, managing message batches, and accessing all modern Anthropic API features.
4
4
 
5
5
  ## Purpose
6
6
 
7
- Wraps the Anthropic Claude REST API as named runners consumable by any LegionIO task chain. Use this extension when you need direct access to the full Anthropic API surface (including async Batches) within the LEX runner/actor lifecycle. For simple chat/embed workflows, consider `legion-llm` instead.
7
+ Wraps the Anthropic Claude REST API as named runners consumable by any LegionIO task chain. Supports streaming, prompt caching, extended thinking, structured output, web search, effort control, fast mode, and all beta API features. For simple chat/embed workflows, consider `legion-llm` instead.
8
8
 
9
9
  ## Installation
10
10
 
@@ -21,23 +21,27 @@ gem 'lex-claude'
21
21
  ## Functions
22
22
 
23
23
  ### Messages
24
- - `create` - Create a message (chat completion) with Claude
25
- - `count_tokens` - Count input tokens for a message request
24
+ - `create` Create a message (supports caching, thinking, tools, structured output)
25
+ - `create_stream` Streaming message creation with SSE event yielding
26
+ - `count_tokens` — Count input tokens (supports tools, thinking, caching)
26
27
 
27
28
  ### Models
28
- - `list` - List available Claude models
29
- - `retrieve` - Get details for a specific model
29
+ - `list` List available Claude models
30
+ - `retrieve` Get details for a specific model
30
31
 
31
32
  ### Batches
32
- - `create_batch` - Create an asynchronous message batch
33
- - `list_batches` - List message batches
34
- - `retrieve_batch` - Get details for a specific batch
35
- - `cancel_batch` - Cancel an in-progress batch
36
- - `batch_results` - Retrieve results for a completed batch
33
+ - `create_batch` Create an asynchronous message batch
34
+ - `list_batches` List message batches
35
+ - `retrieve_batch` Get details for a specific batch
36
+ - `cancel_batch` Cancel an in-progress batch
37
+ - `batch_results` Retrieve results for a completed batch
37
38
 
38
- ## Configuration
39
+ ### Helpers
40
+ - `Helpers::Tools.web_search` — Build web search tool descriptor
41
+ - `Helpers::Models.resolve` — Resolve model Symbol aliases to canonical IDs
42
+ - `Helpers::Errors` — Structured exception hierarchy
39
43
 
40
- Set your API key in your LegionIO settings:
44
+ ## Configuration
41
45
 
42
46
  ```json
43
47
  {
@@ -47,47 +51,150 @@ Set your API key in your LegionIO settings:
47
51
  }
48
52
  ```
49
53
 
50
- ## Standalone Usage
54
+ ## Usage
55
+
56
+ ### Basic message
51
57
 
52
58
  ```ruby
53
59
  require 'legion/extensions/claude/client'
54
60
 
55
61
  client = Legion::Extensions::Claude::Client.new(api_key: ENV['ANTHROPIC_API_KEY'])
56
62
 
57
- # Create a message
58
63
  result = client.create(
59
- model: 'claude-opus-4-6',
60
- messages: [{ role: 'user', content: 'Hello, Claude!' }],
64
+ model: 'claude-sonnet-4-6',
65
+ messages: [{ role: 'user', content: 'Hello!' }],
61
66
  max_tokens: 1024
62
67
  )
63
68
  puts result[:result]['content'].first['text']
69
+ puts result[:usage].inspect
70
+ ```
71
+
72
+ ### Streaming
73
+
74
+ ```ruby
75
+ client.create_stream(
76
+ model: 'claude-sonnet-4-6',
77
+ messages: [{ role: 'user', content: 'Tell me a story.' }],
78
+ max_tokens: 2048
79
+ ) do |event|
80
+ print event[:data].dig('delta', 'text') if event[:event] == 'content_block_delta'
81
+ end
82
+ ```
64
83
 
65
- # List models
66
- models = client.list
67
- puts models[:result]['data'].map { |m| m['id'] }
84
+ ### Prompt caching
85
+
86
+ ```ruby
87
+ result = client.create(
88
+ model: 'claude-sonnet-4-6',
89
+ messages: [{ role: 'user', content: 'Summarize this.' }],
90
+ system: 'You are a helpful assistant with deep context about...',
91
+ cache_system: true,
92
+ cache_scope: :global,
93
+ max_tokens: 512
94
+ )
95
+ puts result[:usage][:cache_read_tokens]
96
+ ```
68
97
 
69
- # Count tokens
70
- tokens = client.count_tokens(
98
+ ### Extended thinking
99
+
100
+ ```ruby
101
+ result = client.create(
71
102
  model: 'claude-opus-4-6',
72
- messages: [{ role: 'user', content: 'How many tokens is this?' }]
103
+ messages: [{ role: 'user', content: 'Solve this complex problem...' }],
104
+ thinking: { type: 'adaptive' },
105
+ max_tokens: 8192
106
+ )
107
+ ```
108
+
109
+ ### Structured output
110
+
111
+ ```ruby
112
+ result = client.create(
113
+ model: 'claude-sonnet-4-6',
114
+ messages: [{ role: 'user', content: 'Extract the name and age.' }],
115
+ max_tokens: 256,
116
+ output_config: {
117
+ format: {
118
+ type: 'json_schema',
119
+ json_schema: {
120
+ type: 'object',
121
+ properties: { name: { type: 'string' }, age: { type: 'integer' } },
122
+ required: %w[name age]
123
+ }
124
+ }
125
+ }
126
+ )
127
+ ```
128
+
129
+ ### Web search
130
+
131
+ ```ruby
132
+ web_tool = Legion::Extensions::Claude::Helpers::Tools.web_search(max_uses: 3)
133
+
134
+ result = client.create(
135
+ model: 'claude-sonnet-4-6',
136
+ messages: [{ role: 'user', content: 'What happened in the news today?' }],
137
+ tools: [web_tool],
138
+ betas: [:web_search],
139
+ max_tokens: 1024
140
+ )
141
+ ```
142
+
143
+ ### Effort control and fast mode
144
+
145
+ ```ruby
146
+ result = client.create(
147
+ model: 'claude-sonnet-4-6',
148
+ messages: messages,
149
+ max_tokens: 2048,
150
+ output_config: { effort: 'high' }
73
151
  )
74
- puts tokens[:result]['input_tokens']
75
-
76
- # Create an async batch
77
- batch = client.create_batch(
78
- requests: [
79
- { custom_id: 'req-1', params: { model: 'claude-opus-4-6',
80
- messages: [{ role: 'user', content: 'Hello' }],
81
- max_tokens: 100 } }
82
- ]
152
+
153
+ result = client.create(
154
+ model: 'claude-sonnet-4-6',
155
+ messages: messages,
156
+ max_tokens: 512,
157
+ fast_mode: true
83
158
  )
84
- puts batch[:result]['id']
159
+ ```
160
+
161
+ ### Beta headers
162
+
163
+ ```ruby
164
+ result = client.create(
165
+ model: 'claude-sonnet-4-6',
166
+ messages: messages,
167
+ max_tokens: 1024,
168
+ betas: [:token_efficient_tools, :advanced_tool_use]
169
+ )
170
+ ```
171
+
172
+ ### Error handling
173
+
174
+ ```ruby
175
+ begin
176
+ result = client.create(model: 'claude-sonnet-4-6', messages: messages, max_tokens: 512)
177
+ rescue Legion::Extensions::Claude::Helpers::Errors::RateLimitError => e
178
+ puts "Rate limited (#{e.status}): #{e.message}"
179
+ rescue Legion::Extensions::Claude::Helpers::Errors::AuthenticationError
180
+ puts 'Check your API key'
181
+ rescue Legion::Extensions::Claude::Helpers::Errors::ApiError => e
182
+ puts "API error #{e.status}: #{e.message}"
183
+ end
184
+ ```
185
+
186
+ ### Auto-retry
187
+
188
+ ```ruby
189
+ result = Legion::Extensions::Claude::Helpers::Retry.with_retry(max_attempts: 3) do
190
+ client.create(model: 'claude-sonnet-4-6', messages: messages, max_tokens: 512)
191
+ end
85
192
  ```
86
193
 
87
194
  ## Dependencies
88
195
 
89
- - `faraday` >= 2.0 - HTTP client
90
- - `multi_json` - JSON parser abstraction
196
+ - `faraday` >= 2.0 HTTP client
197
+ - `multi_json` JSON parser abstraction
91
198
 
92
199
  ## Requirements
93
200
 
@@ -97,8 +204,8 @@ puts batch[:result]['id']
97
204
 
98
205
  ## Related
99
206
 
100
- - `lex-bedrock` — Access Claude models via AWS Bedrock instead of Anthropic directly
101
- - `legion-llm` — High-level LLM interface including Anthropic via ruby_llm
207
+ - `lex-bedrock` — Access Claude models via AWS Bedrock
208
+ - `legion-llm` — High-level LLM interface
102
209
  - `extensions-ai/CLAUDE.md` — Architecture patterns shared across all AI extensions
103
210
 
104
211
  ## License
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'legion/extensions/claude/helpers/client'
4
+ require 'legion/extensions/claude/helpers/models'
4
5
  require 'legion/extensions/claude/runners/messages'
5
6
  require 'legion/extensions/claude/runners/models'
6
7
  require 'legion/extensions/claude/runners/batches'