Skip to content

Commit 16e7336

Browse files
feat(api): add URL source blocks for images and PDFs (#698)
1 parent db6f761 commit 16e7336

File tree

14 files changed

+164
-48
lines changed

14 files changed

+164
-48
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 21
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-e1328d31b4446324096fb948bd5074b5ac00d7c7e3ce89b6974a1c5aebf5a64d.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-129d8719c17bc9ea6e310a63400f60e7ad3ef828e54265eb8a8035684187210b.yml

api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Types:
2020

2121
Types:
2222

23+
- <code><a href="./src/resources/messages/messages.ts">Base64ImageSource</a></code>
2324
- <code><a href="./src/resources/messages/messages.ts">Base64PDFSource</a></code>
2425
- <code><a href="./src/resources/messages/messages.ts">CacheControlEphemeral</a></code>
2526
- <code><a href="./src/resources/messages/messages.ts">CitationCharLocation</a></code>
@@ -84,6 +85,8 @@ Types:
8485
- <code><a href="./src/resources/messages/messages.ts">ToolUnion</a></code>
8586
- <code><a href="./src/resources/messages/messages.ts">ToolUseBlock</a></code>
8687
- <code><a href="./src/resources/messages/messages.ts">ToolUseBlockParam</a></code>
88+
- <code><a href="./src/resources/messages/messages.ts">URLImageSource</a></code>
89+
- <code><a href="./src/resources/messages/messages.ts">URLPDFSource</a></code>
8790
- <code><a href="./src/resources/messages/messages.ts">Usage</a></code>
8891

8992
Methods:
@@ -158,6 +161,7 @@ Methods:
158161

159162
Types:
160163

164+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaBase64ImageSource</a></code>
161165
- <code><a href="./src/resources/beta/messages/messages.ts">BetaBase64PDFBlock</a></code>
162166
- <code><a href="./src/resources/beta/messages/messages.ts">BetaBase64PDFSource</a></code>
163167
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCacheControlEphemeral</a></code>
@@ -217,6 +221,8 @@ Types:
217221
- <code><a href="./src/resources/beta/messages/messages.ts">BetaToolUnion</a></code>
218222
- <code><a href="./src/resources/beta/messages/messages.ts">BetaToolUseBlock</a></code>
219223
- <code><a href="./src/resources/beta/messages/messages.ts">BetaToolUseBlockParam</a></code>
224+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaURLImageSource</a></code>
225+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaURLPDFSource</a></code>
220226
- <code><a href="./src/resources/beta/messages/messages.ts">BetaUsage</a></code>
221227

222228
Methods:

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
BetaRateLimitError,
3232
} from './resources/beta/beta';
3333
import {
34+
Base64ImageSource,
3435
Base64PDFSource,
3536
CacheControlEphemeral,
3637
CitationCharLocation,
@@ -101,6 +102,8 @@ import {
101102
ToolUnion,
102103
ToolUseBlock,
103104
ToolUseBlockParam,
105+
URLImageSource,
106+
URLPDFSource,
104107
Usage,
105108
} from './resources/messages/messages';
106109

@@ -346,6 +349,7 @@ export declare namespace Anthropic {
346349

347350
export {
348351
Messages as Messages,
352+
type Base64ImageSource as Base64ImageSource,
349353
type Base64PDFSource as Base64PDFSource,
350354
type CacheControlEphemeral as CacheControlEphemeral,
351355
type CitationCharLocation as CitationCharLocation,
@@ -410,6 +414,8 @@ export declare namespace Anthropic {
410414
type ToolUnion as ToolUnion,
411415
type ToolUseBlock as ToolUseBlock,
412416
type ToolUseBlockParam as ToolUseBlockParam,
417+
type URLImageSource as URLImageSource,
418+
type URLPDFSource as URLPDFSource,
413419
type Usage as Usage,
414420
type MessageCreateParams as MessageCreateParams,
415421
type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,

src/resources/beta/beta.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as ModelsAPI from './models';
55
import { BetaModelInfo, BetaModelInfosPage, ModelListParams, Models } from './models';
66
import * as MessagesAPI from './messages/messages';
77
import {
8+
BetaBase64ImageSource,
89
BetaBase64PDFBlock,
910
BetaBase64PDFSource,
1011
BetaCacheControlEphemeral,
@@ -64,6 +65,8 @@ import {
6465
BetaToolUnion,
6566
BetaToolUseBlock,
6667
BetaToolUseBlockParam,
68+
BetaURLImageSource,
69+
BetaURLPDFSource,
6770
BetaUsage,
6871
MessageCountTokensParams,
6972
MessageCreateParams,
@@ -188,6 +191,7 @@ export declare namespace Beta {
188191

189192
export {
190193
Messages as Messages,
194+
type BetaBase64ImageSource as BetaBase64ImageSource,
191195
type BetaBase64PDFBlock as BetaBase64PDFBlock,
192196
type BetaBase64PDFSource as BetaBase64PDFSource,
193197
type BetaCacheControlEphemeral as BetaCacheControlEphemeral,
@@ -247,6 +251,8 @@ export declare namespace Beta {
247251
type BetaToolUnion as BetaToolUnion,
248252
type BetaToolUseBlock as BetaToolUseBlock,
249253
type BetaToolUseBlockParam as BetaToolUseBlockParam,
254+
type BetaURLImageSource as BetaURLImageSource,
255+
type BetaURLPDFSource as BetaURLPDFSource,
250256
type BetaUsage as BetaUsage,
251257
type MessageCreateParams as MessageCreateParams,
252258
type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,

src/resources/beta/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export {
1818
export { BetaModelInfosPage, Models, type BetaModelInfo, type ModelListParams } from './models';
1919
export {
2020
Messages,
21+
type BetaBase64ImageSource,
2122
type BetaBase64PDFBlock,
2223
type BetaBase64PDFSource,
2324
type BetaCacheControlEphemeral,
@@ -77,6 +78,8 @@ export {
7778
type BetaToolUnion,
7879
type BetaToolUseBlock,
7980
type BetaToolUseBlockParam,
81+
type BetaURLImageSource,
82+
type BetaURLPDFSource,
8083
type BetaUsage,
8184
type MessageCreateParams,
8285
type MessageCreateParamsNonStreaming,

src/resources/beta/messages/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export {
2121
} from './batches';
2222
export {
2323
Messages,
24+
type BetaBase64ImageSource,
2425
type BetaBase64PDFBlock,
2526
type BetaBase64PDFSource,
2627
type BetaCacheControlEphemeral,
@@ -80,6 +81,8 @@ export {
8081
type BetaToolUnion,
8182
type BetaToolUseBlock,
8283
type BetaToolUseBlockParam,
84+
type BetaURLImageSource,
85+
type BetaURLPDFSource,
8386
type BetaUsage,
8487
type MessageCreateParams,
8588
type MessageCreateParamsNonStreaming,

src/resources/beta/messages/messages.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,16 @@ export class Messages extends APIResource {
126126

127127
export type BetaMessageStreamParams = MessageCreateParamsBase;
128128

129+
export interface BetaBase64ImageSource {
130+
data: string;
131+
132+
media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
133+
134+
type: 'base64';
135+
}
136+
129137
export interface BetaBase64PDFBlock {
130-
source: BetaBase64PDFSource | BetaPlainTextSource | BetaContentBlockSource;
138+
source: BetaBase64PDFSource | BetaPlainTextSource | BetaContentBlockSource | BetaURLPDFSource;
131139

132140
type: 'document';
133141

@@ -270,23 +278,13 @@ export interface BetaContentBlockSource {
270278
export type BetaContentBlockSourceContent = BetaTextBlockParam | BetaImageBlockParam;
271279

272280
export interface BetaImageBlockParam {
273-
source: BetaImageBlockParam.Source;
281+
source: BetaBase64ImageSource | BetaURLImageSource;
274282

275283
type: 'image';
276284

277285
cache_control?: BetaCacheControlEphemeral | null;
278286
}
279287

280-
export namespace BetaImageBlockParam {
281-
export interface Source {
282-
data: string;
283-
284-
media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
285-
286-
type: 'base64';
287-
}
288-
}
289-
290288
export interface BetaInputJSONDelta {
291289
partial_json: string;
292290

@@ -852,13 +850,13 @@ export interface BetaToolTextEditor20250124 {
852850
}
853851

854852
export type BetaToolUnion =
853+
| BetaTool
855854
| BetaToolComputerUse20241022
856855
| BetaToolBash20241022
857856
| BetaToolTextEditor20241022
858857
| BetaToolComputerUse20250124
859858
| BetaToolBash20250124
860-
| BetaToolTextEditor20250124
861-
| BetaTool;
859+
| BetaToolTextEditor20250124;
862860

863861
export interface BetaToolUseBlock {
864862
id: string;
@@ -882,6 +880,18 @@ export interface BetaToolUseBlockParam {
882880
cache_control?: BetaCacheControlEphemeral | null;
883881
}
884882

883+
export interface BetaURLImageSource {
884+
type: 'url';
885+
886+
url: string;
887+
}
888+
889+
export interface BetaURLPDFSource {
890+
type: 'url';
891+
892+
url: string;
893+
}
894+
885895
export interface BetaUsage {
886896
/**
887897
* The number of input tokens used to create the cache entry.
@@ -1410,13 +1420,13 @@ export interface MessageCountTokensParams {
14101420
* See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
14111421
*/
14121422
tools?: Array<
1423+
| BetaTool
14131424
| BetaToolComputerUse20241022
14141425
| BetaToolBash20241022
14151426
| BetaToolTextEditor20241022
14161427
| BetaToolComputerUse20250124
14171428
| BetaToolBash20250124
14181429
| BetaToolTextEditor20250124
1419-
| BetaTool
14201430
>;
14211431

14221432
/**
@@ -1430,6 +1440,7 @@ Messages.BetaMessageBatchesPage = BetaMessageBatchesPage;
14301440

14311441
export declare namespace Messages {
14321442
export {
1443+
type BetaBase64ImageSource as BetaBase64ImageSource,
14331444
type BetaBase64PDFBlock as BetaBase64PDFBlock,
14341445
type BetaBase64PDFSource as BetaBase64PDFSource,
14351446
type BetaCacheControlEphemeral as BetaCacheControlEphemeral,
@@ -1489,6 +1500,8 @@ export declare namespace Messages {
14891500
type BetaToolUnion as BetaToolUnion,
14901501
type BetaToolUseBlock as BetaToolUseBlock,
14911502
type BetaToolUseBlockParam as BetaToolUseBlockParam,
1503+
type BetaURLImageSource as BetaURLImageSource,
1504+
type BetaURLPDFSource as BetaURLPDFSource,
14921505
type BetaUsage as BetaUsage,
14931506
type MessageCreateParams as MessageCreateParams,
14941507
type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,

src/resources/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export {
2525
} from './completions';
2626
export {
2727
Messages,
28+
type Base64ImageSource,
2829
type Base64PDFSource,
2930
type CacheControlEphemeral,
3031
type CitationCharLocation,
@@ -91,6 +92,8 @@ export {
9192
type ToolUnion,
9293
type ToolUseBlock,
9394
type ToolUseBlockParam,
95+
type URLImageSource,
96+
type URLPDFSource,
9497
type Usage,
9598
type MessageCreateParams,
9699
type MessageCreateParamsNonStreaming,

src/resources/messages/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export {
1717
} from './batches';
1818
export {
1919
Messages,
20+
type Base64ImageSource,
2021
type Base64PDFSource,
2122
type CacheControlEphemeral,
2223
type CitationCharLocation,
@@ -81,6 +82,8 @@ export {
8182
type ToolUnion,
8283
type ToolUseBlock,
8384
type ToolUseBlockParam,
85+
type URLImageSource,
86+
type URLPDFSource,
8487
type Usage,
8588
type MessageCreateParams,
8689
type MessageCreateParamsBase,

src/resources/messages/messages.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ export class Messages extends APIResource {
9191
}
9292
}
9393

94+
export interface Base64ImageSource {
95+
data: string;
96+
97+
media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
98+
99+
type: 'base64';
100+
}
101+
94102
export interface Base64PDFSource {
95103
data: string;
96104

@@ -223,7 +231,7 @@ export type ContentBlockStartEvent = RawContentBlockStartEvent;
223231
export type ContentBlockStopEvent = RawContentBlockStopEvent;
224232

225233
export interface DocumentBlockParam {
226-
source: Base64PDFSource | PlainTextSource | ContentBlockSource;
234+
source: Base64PDFSource | PlainTextSource | ContentBlockSource | URLPDFSource;
227235

228236
type: 'document';
229237

@@ -237,23 +245,13 @@ export interface DocumentBlockParam {
237245
}
238246

239247
export interface ImageBlockParam {
240-
source: ImageBlockParam.Source;
248+
source: Base64ImageSource | URLImageSource;
241249

242250
type: 'image';
243251

244252
cache_control?: CacheControlEphemeral | null;
245253
}
246254

247-
export namespace ImageBlockParam {
248-
export interface Source {
249-
data: string;
250-
251-
media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
252-
253-
type: 'base64';
254-
}
255-
}
256-
257255
export type InputJsonDelta = InputJSONDelta;
258256

259257
export interface InputJSONDelta {
@@ -370,7 +368,7 @@ export interface Message {
370368
usage: Usage;
371369
}
372370

373-
export type MessageCountTokensTool = ToolBash20250124 | ToolTextEditor20250124 | Tool;
371+
export type MessageCountTokensTool = Tool | ToolBash20250124 | ToolTextEditor20250124;
374372

375373
export type MessageDeltaEvent = RawMessageDeltaEvent;
376374

@@ -777,7 +775,7 @@ export interface ToolTextEditor20250124 {
777775
cache_control?: CacheControlEphemeral | null;
778776
}
779777

780-
export type ToolUnion = ToolBash20250124 | ToolTextEditor20250124 | Tool;
778+
export type ToolUnion = Tool | ToolBash20250124 | ToolTextEditor20250124;
781779

782780
export interface ToolUseBlock {
783781
id: string;
@@ -801,6 +799,18 @@ export interface ToolUseBlockParam {
801799
cache_control?: CacheControlEphemeral | null;
802800
}
803801

802+
export interface URLImageSource {
803+
type: 'url';
804+
805+
url: string;
806+
}
807+
808+
export interface URLPDFSource {
809+
type: 'url';
810+
811+
url: string;
812+
}
813+
804814
export interface Usage {
805815
/**
806816
* The number of input tokens used to create the cache entry.
@@ -1350,6 +1360,7 @@ Messages.MessageBatchesPage = MessageBatchesPage;
13501360

13511361
export declare namespace Messages {
13521362
export {
1363+
type Base64ImageSource as Base64ImageSource,
13531364
type Base64PDFSource as Base64PDFSource,
13541365
type CacheControlEphemeral as CacheControlEphemeral,
13551366
type CitationCharLocation as CitationCharLocation,
@@ -1415,6 +1426,8 @@ export declare namespace Messages {
14151426
type ToolUnion as ToolUnion,
14161427
type ToolUseBlock as ToolUseBlock,
14171428
type ToolUseBlockParam as ToolUseBlockParam,
1429+
type URLImageSource as URLImageSource,
1430+
type URLPDFSource as URLPDFSource,
14181431
type Usage as Usage,
14191432
type MessageCreateParams as MessageCreateParams,
14201433
type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,

0 commit comments

Comments
 (0)