Skip to content

Commit de4f483

Browse files
docs: improve examples
1 parent 1933857 commit de4f483

File tree

19 files changed

+151
-68
lines changed

19 files changed

+151
-68
lines changed

src/resources/beta/messages/messages.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,14 @@ export class Messages extends APIResource {
200200
* ```ts
201201
* const betaMessageTokensCount =
202202
* await client.beta.messages.countTokens({
203-
* messages: [{ content: 'string', role: 'user' }],
203+
* messages: [
204+
* {
205+
* content: [
206+
* { text: 'What is a quaternion?', type: 'text' },
207+
* ],
208+
* role: 'user',
209+
* },
210+
* ],
204211
* model: 'claude-mythos-preview',
205212
* });
206213
* ```

src/resources/messages/messages.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,14 @@ export class Messages extends APIResource {
176176
* ```ts
177177
* const messageTokensCount =
178178
* await client.messages.countTokens({
179-
* messages: [{ content: 'string', role: 'user' }],
179+
* messages: [
180+
* {
181+
* content: [
182+
* { text: 'What is a quaternion?', type: 'text' },
183+
* ],
184+
* role: 'user',
185+
* },
186+
* ],
180187
* model: 'claude-mythos-preview',
181188
* });
182189
* ```

tests/api-resources/beta/agents/agents.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('resource agents', () => {
5757
},
5858
},
5959
],
60-
betas: ['string'],
60+
betas: ['message-batches-2024-09-24'],
6161
});
6262
});
6363

@@ -79,7 +79,7 @@ describe('resource agents', () => {
7979
await expect(
8080
client.beta.agents.retrieve(
8181
'agent_011CZkYpogX7uDKUyvBTophP',
82-
{ version: 0, betas: ['string'] },
82+
{ version: 0, betas: ['message-batches-2024-09-24'] },
8383
{ path: '/_stainless_unknown_path' },
8484
),
8585
).rejects.toThrow(Anthropic.NotFoundError);
@@ -108,7 +108,7 @@ describe('resource agents', () => {
108108
},
109109
],
110110
metadata: { foo: 'string' },
111-
model: 'claude-opus-4-6',
111+
model: { id: 'claude-opus-4-6', speed: 'standard' },
112112
name: 'name',
113113
skills: [
114114
{
@@ -135,7 +135,7 @@ describe('resource agents', () => {
135135
},
136136
},
137137
],
138-
betas: ['string'],
138+
betas: ['message-batches-2024-09-24'],
139139
});
140140
});
141141

@@ -162,7 +162,7 @@ describe('resource agents', () => {
162162
include_archived: true,
163163
limit: 0,
164164
page: 'page',
165-
betas: ['string'],
165+
betas: ['message-batches-2024-09-24'],
166166
},
167167
{ path: '/_stainless_unknown_path' },
168168
),
@@ -185,7 +185,7 @@ describe('resource agents', () => {
185185
await expect(
186186
client.beta.agents.archive(
187187
'agent_011CZkYpogX7uDKUyvBTophP',
188-
{ betas: ['string'] },
188+
{ betas: ['message-batches-2024-09-24'] },
189189
{ path: '/_stainless_unknown_path' },
190190
),
191191
).rejects.toThrow(Anthropic.NotFoundError);

tests/api-resources/beta/agents/versions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('resource versions', () => {
2929
{
3030
limit: 0,
3131
page: 'page',
32-
betas: ['string'],
32+
betas: ['message-batches-2024-09-24'],
3333
},
3434
{ path: '/_stainless_unknown_path' },
3535
),

tests/api-resources/beta/environments.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('resource environments', () => {
4242
},
4343
description: 'Python environment with data-analysis packages.',
4444
metadata: { foo: 'string' },
45-
betas: ['string'],
45+
betas: ['message-batches-2024-09-24'],
4646
});
4747
});
4848

@@ -62,7 +62,7 @@ describe('resource environments', () => {
6262
await expect(
6363
client.beta.environments.retrieve(
6464
'env_011CZkZ9X2dpNyB7HsEFoRfW',
65-
{ betas: ['string'] },
65+
{ betas: ['message-batches-2024-09-24'] },
6666
{ path: '/_stainless_unknown_path' },
6767
),
6868
).rejects.toThrow(Anthropic.NotFoundError);
@@ -98,7 +98,7 @@ describe('resource environments', () => {
9898
include_archived: true,
9999
limit: 1,
100100
page: 'page',
101-
betas: ['string'],
101+
betas: ['message-batches-2024-09-24'],
102102
},
103103
{ path: '/_stainless_unknown_path' },
104104
),
@@ -121,7 +121,7 @@ describe('resource environments', () => {
121121
await expect(
122122
client.beta.environments.delete(
123123
'env_011CZkZ9X2dpNyB7HsEFoRfW',
124-
{ betas: ['string'] },
124+
{ betas: ['message-batches-2024-09-24'] },
125125
{ path: '/_stainless_unknown_path' },
126126
),
127127
).rejects.toThrow(Anthropic.NotFoundError);
@@ -143,7 +143,7 @@ describe('resource environments', () => {
143143
await expect(
144144
client.beta.environments.archive(
145145
'env_011CZkZ9X2dpNyB7HsEFoRfW',
146-
{ betas: ['string'] },
146+
{ betas: ['message-batches-2024-09-24'] },
147147
{ path: '/_stainless_unknown_path' },
148148
),
149149
).rejects.toThrow(Anthropic.NotFoundError);

tests/api-resources/beta/files.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('resource files', () => {
2828
before_id: 'before_id',
2929
limit: 1,
3030
scope_id: 'scope_id',
31-
betas: ['string'],
31+
betas: ['message-batches-2024-09-24'],
3232
},
3333
{ path: '/_stainless_unknown_path' },
3434
),
@@ -49,14 +49,22 @@ describe('resource files', () => {
4949
test('delete: request options and params are passed correctly', async () => {
5050
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
5151
await expect(
52-
client.beta.files.delete('file_id', { betas: ['string'] }, { path: '/_stainless_unknown_path' }),
52+
client.beta.files.delete(
53+
'file_id',
54+
{ betas: ['message-batches-2024-09-24'] },
55+
{ path: '/_stainless_unknown_path' },
56+
),
5357
).rejects.toThrow(Anthropic.NotFoundError);
5458
});
5559

5660
test('download: request options and params are passed correctly', async () => {
5761
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
5862
await expect(
59-
client.beta.files.download('file_id', { betas: ['string'] }, { path: '/_stainless_unknown_path' }),
63+
client.beta.files.download(
64+
'file_id',
65+
{ betas: ['message-batches-2024-09-24'] },
66+
{ path: '/_stainless_unknown_path' },
67+
),
6068
).rejects.toThrow(Anthropic.NotFoundError);
6169
});
6270

@@ -76,7 +84,7 @@ describe('resource files', () => {
7684
await expect(
7785
client.beta.files.retrieveMetadata(
7886
'file_id',
79-
{ betas: ['string'] },
87+
{ betas: ['message-batches-2024-09-24'] },
8088
{ path: '/_stainless_unknown_path' },
8189
),
8290
).rejects.toThrow(Anthropic.NotFoundError);
@@ -98,7 +106,7 @@ describe('resource files', () => {
98106
test('upload: required and optional params', async () => {
99107
const response = await client.beta.files.upload({
100108
file: await toFile(Buffer.from('Example data'), 'README.md'),
101-
betas: ['string'],
109+
betas: ['message-batches-2024-09-24'],
102110
});
103111
});
104112
});

tests/api-resources/beta/messages/batches.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('resource batches', () => {
132132
},
133133
},
134134
],
135-
betas: ['string'],
135+
betas: ['message-batches-2024-09-24'],
136136
});
137137
});
138138

@@ -152,7 +152,7 @@ describe('resource batches', () => {
152152
await expect(
153153
client.beta.messages.batches.retrieve(
154154
'message_batch_id',
155-
{ betas: ['string'] },
155+
{ betas: ['message-batches-2024-09-24'] },
156156
{ path: '/_stainless_unknown_path' },
157157
),
158158
).rejects.toThrow(Anthropic.NotFoundError);
@@ -177,7 +177,7 @@ describe('resource batches', () => {
177177
after_id: 'after_id',
178178
before_id: 'before_id',
179179
limit: 1,
180-
betas: ['string'],
180+
betas: ['message-batches-2024-09-24'],
181181
},
182182
{ path: '/_stainless_unknown_path' },
183183
),
@@ -200,7 +200,7 @@ describe('resource batches', () => {
200200
await expect(
201201
client.beta.messages.batches.delete(
202202
'message_batch_id',
203-
{ betas: ['string'] },
203+
{ betas: ['message-batches-2024-09-24'] },
204204
{ path: '/_stainless_unknown_path' },
205205
),
206206
).rejects.toThrow(Anthropic.NotFoundError);
@@ -222,7 +222,7 @@ describe('resource batches', () => {
222222
await expect(
223223
client.beta.messages.batches.cancel(
224224
'message_batch_id',
225-
{ betas: ['string'] },
225+
{ betas: ['message-batches-2024-09-24'] },
226226
{ path: '/_stainless_unknown_path' },
227227
),
228228
).rejects.toThrow(Anthropic.NotFoundError);
@@ -265,7 +265,7 @@ describe('resource batches', () => {
265265
await expect(
266266
client.beta.messages.batches.results(
267267
'message_batch_id',
268-
{ betas: ['string'] },
268+
{ betas: ['message-batches-2024-09-24'] },
269269
{ path: '/_stainless_unknown_path' },
270270
),
271271
).rejects.toThrow(Anthropic.NotFoundError);

tests/api-resources/beta/messages/messages.test.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ describe('resource messages', () => {
113113
],
114114
top_k: 5,
115115
top_p: 0.7,
116-
betas: ['string'],
116+
betas: ['message-batches-2024-09-24'],
117117
});
118118
});
119119

120120
test('countTokens: only required params', async () => {
121121
const responsePromise = client.beta.messages.countTokens({
122-
messages: [{ content: 'string', role: 'user' }],
122+
messages: [{ content: [{ text: 'What is a quaternion?', type: 'text' }], role: 'user' }],
123123
model: 'claude-mythos-preview',
124124
});
125125
const rawResponse = await responsePromise.asResponse();
@@ -133,7 +133,28 @@ describe('resource messages', () => {
133133

134134
test('countTokens: required and optional params', async () => {
135135
const response = await client.beta.messages.countTokens({
136-
messages: [{ content: 'string', role: 'user' }],
136+
messages: [
137+
{
138+
content: [
139+
{
140+
text: 'What is a quaternion?',
141+
type: 'text',
142+
cache_control: { type: 'ephemeral', ttl: '5m' },
143+
citations: [
144+
{
145+
cited_text: 'cited_text',
146+
document_index: 0,
147+
document_title: 'x',
148+
end_char_index: 0,
149+
start_char_index: 0,
150+
type: 'char_location',
151+
},
152+
],
153+
},
154+
],
155+
role: 'user',
156+
},
157+
],
137158
model: 'claude-mythos-preview',
138159
cache_control: { type: 'ephemeral', ttl: '5m' },
139160
context_management: {
@@ -202,7 +223,7 @@ describe('resource messages', () => {
202223
type: 'custom',
203224
},
204225
],
205-
betas: ['string'],
226+
betas: ['message-batches-2024-09-24'],
206227
});
207228
});
208229
});

tests/api-resources/beta/models.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ describe('resource models', () => {
2222
test('retrieve: request options and params are passed correctly', async () => {
2323
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
2424
await expect(
25-
client.beta.models.retrieve('model_id', { betas: ['string'] }, { path: '/_stainless_unknown_path' }),
25+
client.beta.models.retrieve(
26+
'model_id',
27+
{ betas: ['message-batches-2024-09-24'] },
28+
{ path: '/_stainless_unknown_path' },
29+
),
2630
).rejects.toThrow(Anthropic.NotFoundError);
2731
});
2832

@@ -52,7 +56,7 @@ describe('resource models', () => {
5256
after_id: 'after_id',
5357
before_id: 'before_id',
5458
limit: 1,
55-
betas: ['string'],
59+
betas: ['message-batches-2024-09-24'],
5660
},
5761
{ path: '/_stainless_unknown_path' },
5862
),

tests/api-resources/beta/sessions/events.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('resource events', () => {
3030
limit: 0,
3131
order: 'asc',
3232
page: 'page',
33-
betas: ['string'],
33+
betas: ['message-batches-2024-09-24'],
3434
},
3535
{ path: '/_stainless_unknown_path' },
3636
),
@@ -53,7 +53,7 @@ describe('resource events', () => {
5353
test('send: required and optional params', async () => {
5454
const response = await client.beta.sessions.events.send('sesn_011CZkZAtmR3yMPDzynEDxu7', {
5555
events: [{ content: [{ text: 'Where is my order #1234?', type: 'text' }], type: 'user.message' }],
56-
betas: ['string'],
56+
betas: ['message-batches-2024-09-24'],
5757
});
5858
});
5959

@@ -73,7 +73,7 @@ describe('resource events', () => {
7373
await expect(
7474
client.beta.sessions.events.stream(
7575
'sesn_011CZkZAtmR3yMPDzynEDxu7',
76-
{ betas: ['string'] },
76+
{ betas: ['message-batches-2024-09-24'] },
7777
{ path: '/_stainless_unknown_path' },
7878
),
7979
).rejects.toThrow(Anthropic.NotFoundError);

0 commit comments

Comments
 (0)