Skip to content

Commit 67aa83e

Browse files
feat(api): add citations (#839)
1 parent bb1f52b commit 67aa83e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+765
-31
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-75f0573c3d6d79650bcbd8b1b4fcf93ce146d567afeb1061cd4afccf8d1d6799.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-7270ee0a79d885681ee507414608229f61c27f47c40f355dcd210b38aa7cddf1.yml

api.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@ Types:
2424
from anthropic.types import (
2525
Base64PDFSource,
2626
CacheControlEphemeral,
27+
CitationCharLocation,
28+
CitationCharLocationParam,
29+
CitationContentBlockLocation,
30+
CitationContentBlockLocationParam,
31+
CitationPageLocation,
32+
CitationPageLocationParam,
33+
CitationsConfigParam,
34+
CitationsDelta,
2735
ContentBlock,
2836
ContentBlockDeltaEvent,
2937
ContentBlockParam,
38+
ContentBlockSource,
39+
ContentBlockSourceContent,
3040
ContentBlockStartEvent,
3141
ContentBlockStopEvent,
3242
DocumentBlockParam,
@@ -42,6 +52,7 @@ from anthropic.types import (
4252
MessageTokensCount,
4353
Metadata,
4454
Model,
55+
PlainTextSource,
4556
RawContentBlockDeltaEvent,
4657
RawContentBlockStartEvent,
4758
RawContentBlockStopEvent,
@@ -51,6 +62,8 @@ from anthropic.types import (
5162
RawMessageStreamEvent,
5263
TextBlock,
5364
TextBlockParam,
65+
TextCitation,
66+
TextCitationParam,
5467
TextDelta,
5568
Tool,
5669
ToolChoice,
@@ -153,15 +166,26 @@ from anthropic.types.beta import (
153166
BetaBase64PDFBlock,
154167
BetaBase64PDFSource,
155168
BetaCacheControlEphemeral,
169+
BetaCitationCharLocation,
170+
BetaCitationCharLocationParam,
171+
BetaCitationContentBlockLocation,
172+
BetaCitationContentBlockLocationParam,
173+
BetaCitationPageLocation,
174+
BetaCitationPageLocationParam,
175+
BetaCitationsConfigParam,
176+
BetaCitationsDelta,
156177
BetaContentBlock,
157178
BetaContentBlockParam,
179+
BetaContentBlockSource,
180+
BetaContentBlockSourceContent,
158181
BetaImageBlockParam,
159182
BetaInputJSONDelta,
160183
BetaMessage,
161184
BetaMessageDeltaUsage,
162185
BetaMessageParam,
163186
BetaMessageTokensCount,
164187
BetaMetadata,
188+
BetaPlainTextSource,
165189
BetaRawContentBlockDeltaEvent,
166190
BetaRawContentBlockStartEvent,
167191
BetaRawContentBlockStopEvent,
@@ -171,6 +195,8 @@ from anthropic.types.beta import (
171195
BetaRawMessageStreamEvent,
172196
BetaTextBlock,
173197
BetaTextBlockParam,
198+
BetaTextCitation,
199+
BetaTextCitationParam,
174200
BetaTextDelta,
175201
BetaTool,
176202
BetaToolBash20241022,

src/anthropic/resources/beta/messages/batches.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ def delete(
239239
extra_body: Body | None = None,
240240
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
241241
) -> BetaDeletedMessageBatch:
242-
"""This endpoint is idempotent and can be used to poll for Message Batch
243-
completion.
242+
"""
243+
Delete a Message Batch.
244244
245-
To access the results of a Message Batch, make a request to the
246-
`results_url` field in the response.
245+
Message Batches can only be deleted once they've finished processing. If you'd
246+
like to delete an in-progress batch, you must first cancel it.
247247
248248
Args:
249249
message_batch_id: ID of the Message Batch.
@@ -608,11 +608,11 @@ async def delete(
608608
extra_body: Body | None = None,
609609
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
610610
) -> BetaDeletedMessageBatch:
611-
"""This endpoint is idempotent and can be used to poll for Message Batch
612-
completion.
611+
"""
612+
Delete a Message Batch.
613613
614-
To access the results of a Message Batch, make a request to the
615-
`results_url` field in the response.
614+
Message Batches can only be deleted once they've finished processing. If you'd
615+
like to delete an in-progress batch, you must first cancel it.
616616
617617
Args:
618618
message_batch_id: ID of the Message Batch.

src/anthropic/resources/messages/batches.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ def delete(
192192
extra_body: Body | None = None,
193193
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
194194
) -> DeletedMessageBatch:
195-
"""This endpoint is idempotent and can be used to poll for Message Batch
196-
completion.
195+
"""
196+
Delete a Message Batch.
197197
198-
To access the results of a Message Batch, make a request to the
199-
`results_url` field in the response.
198+
Message Batches can only be deleted once they've finished processing. If you'd
199+
like to delete an in-progress batch, you must first cancel it.
200200
201201
Args:
202202
message_batch_id: ID of the Message Batch.
@@ -477,11 +477,11 @@ async def delete(
477477
extra_body: Body | None = None,
478478
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
479479
) -> DeletedMessageBatch:
480-
"""This endpoint is idempotent and can be used to poll for Message Batch
481-
completion.
480+
"""
481+
Delete a Message Batch.
482482
483-
To access the results of a Message Batch, make a request to the
484-
`results_url` field in the response.
483+
Message Batches can only be deleted once they've finished processing. If you'd
484+
like to delete an in-progress batch, you must first cancel it.
485485
486486
Args:
487487
message_batch_id: ID of the Message Batch.

src/anthropic/types/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
from .model_param import ModelParam as ModelParam
2828
from .content_block import ContentBlock as ContentBlock
2929
from .message_param import MessageParam as MessageParam
30+
from .text_citation import TextCitation as TextCitation
3031
from .beta_api_error import BetaAPIError as BetaAPIError
3132
from .metadata_param import MetadataParam as MetadataParam
3233
from .tool_use_block import ToolUseBlock as ToolUseBlock
34+
from .citations_delta import CitationsDelta as CitationsDelta
3335
from .input_json_delta import InputJSONDelta as InputJSONDelta
3436
from .text_block_param import TextBlockParam as TextBlockParam
3537
from .image_block_param import ImageBlockParam as ImageBlockParam
@@ -42,6 +44,7 @@
4244
from .message_delta_event import MessageDeltaEvent as MessageDeltaEvent
4345
from .message_delta_usage import MessageDeltaUsage as MessageDeltaUsage
4446
from .message_start_event import MessageStartEvent as MessageStartEvent
47+
from .text_citation_param import TextCitationParam as TextCitationParam
4548
from .anthropic_beta_param import AnthropicBetaParam as AnthropicBetaParam
4649
from .beta_not_found_error import BetaNotFoundError as BetaNotFoundError
4750
from .document_block_param import DocumentBlockParam as DocumentBlockParam
@@ -53,10 +56,14 @@
5356
from .beta_rate_limit_error import BetaRateLimitError as BetaRateLimitError
5457
from .message_create_params import MessageCreateParams as MessageCreateParams
5558
from .tool_choice_any_param import ToolChoiceAnyParam as ToolChoiceAnyParam
59+
from .citation_char_location import CitationCharLocation as CitationCharLocation
60+
from .citation_page_location import CitationPageLocation as CitationPageLocation
61+
from .citations_config_param import CitationsConfigParam as CitationsConfigParam
5662
from .raw_message_stop_event import RawMessageStopEvent as RawMessageStopEvent
5763
from .tool_choice_auto_param import ToolChoiceAutoParam as ToolChoiceAutoParam
5864
from .tool_choice_tool_param import ToolChoiceToolParam as ToolChoiceToolParam
5965
from .base64_pdf_source_param import Base64PDFSourceParam as Base64PDFSourceParam
66+
from .plain_text_source_param import PlainTextSourceParam as PlainTextSourceParam
6067
from .raw_message_delta_event import RawMessageDeltaEvent as RawMessageDeltaEvent
6168
from .raw_message_start_event import RawMessageStartEvent as RawMessageStartEvent
6269
from .tool_result_block_param import ToolResultBlockParam as ToolResultBlockParam
@@ -68,8 +75,16 @@
6875
from .content_block_start_event import ContentBlockStartEvent as ContentBlockStartEvent
6976
from .beta_gateway_timeout_error import BetaGatewayTimeoutError as BetaGatewayTimeoutError
7077
from .beta_invalid_request_error import BetaInvalidRequestError as BetaInvalidRequestError
78+
from .content_block_source_param import ContentBlockSourceParam as ContentBlockSourceParam
7179
from .message_count_tokens_params import MessageCountTokensParams as MessageCountTokensParams
80+
from .citation_char_location_param import CitationCharLocationParam as CitationCharLocationParam
81+
from .citation_page_location_param import CitationPageLocationParam as CitationPageLocationParam
7282
from .raw_content_block_stop_event import RawContentBlockStopEvent as RawContentBlockStopEvent
7383
from .cache_control_ephemeral_param import CacheControlEphemeralParam as CacheControlEphemeralParam
7484
from .raw_content_block_delta_event import RawContentBlockDeltaEvent as RawContentBlockDeltaEvent
7585
from .raw_content_block_start_event import RawContentBlockStartEvent as RawContentBlockStartEvent
86+
from .citation_content_block_location import CitationContentBlockLocation as CitationContentBlockLocation
87+
from .content_block_source_content_param import ContentBlockSourceContentParam as ContentBlockSourceContentParam
88+
from .citation_content_block_location_param import (
89+
CitationContentBlockLocationParam as CitationContentBlockLocationParam,
90+
)

src/anthropic/types/beta/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
from .model_list_params import ModelListParams as ModelListParams
1212
from .beta_content_block import BetaContentBlock as BetaContentBlock
1313
from .beta_message_param import BetaMessageParam as BetaMessageParam
14+
from .beta_text_citation import BetaTextCitation as BetaTextCitation
1415
from .beta_metadata_param import BetaMetadataParam as BetaMetadataParam
1516
from .beta_tool_use_block import BetaToolUseBlock as BetaToolUseBlock
17+
from .beta_citations_delta import BetaCitationsDelta as BetaCitationsDelta
1618
from .beta_input_json_delta import BetaInputJSONDelta as BetaInputJSONDelta
1719
from .beta_text_block_param import BetaTextBlockParam as BetaTextBlockParam
1820
from .beta_tool_union_param import BetaToolUnionParam as BetaToolUnionParam
@@ -21,23 +23,38 @@
2123
from .beta_tool_choice_param import BetaToolChoiceParam as BetaToolChoiceParam
2224
from .beta_content_block_param import BetaContentBlockParam as BetaContentBlockParam
2325
from .beta_message_delta_usage import BetaMessageDeltaUsage as BetaMessageDeltaUsage
26+
from .beta_text_citation_param import BetaTextCitationParam as BetaTextCitationParam
2427
from .beta_message_tokens_count import BetaMessageTokensCount as BetaMessageTokensCount
2528
from .beta_tool_use_block_param import BetaToolUseBlockParam as BetaToolUseBlockParam
2629
from .beta_tool_choice_any_param import BetaToolChoiceAnyParam as BetaToolChoiceAnyParam
2730
from .beta_base64_pdf_block_param import BetaBase64PDFBlockParam as BetaBase64PDFBlockParam
31+
from .beta_citation_char_location import BetaCitationCharLocation as BetaCitationCharLocation
32+
from .beta_citation_page_location import BetaCitationPageLocation as BetaCitationPageLocation
33+
from .beta_citations_config_param import BetaCitationsConfigParam as BetaCitationsConfigParam
2834
from .beta_raw_message_stop_event import BetaRawMessageStopEvent as BetaRawMessageStopEvent
2935
from .beta_tool_choice_auto_param import BetaToolChoiceAutoParam as BetaToolChoiceAutoParam
3036
from .beta_tool_choice_tool_param import BetaToolChoiceToolParam as BetaToolChoiceToolParam
3137
from .message_count_tokens_params import MessageCountTokensParams as MessageCountTokensParams
3238
from .beta_base64_pdf_source_param import BetaBase64PDFSourceParam as BetaBase64PDFSourceParam
39+
from .beta_plain_text_source_param import BetaPlainTextSourceParam as BetaPlainTextSourceParam
3340
from .beta_raw_message_delta_event import BetaRawMessageDeltaEvent as BetaRawMessageDeltaEvent
3441
from .beta_raw_message_start_event import BetaRawMessageStartEvent as BetaRawMessageStartEvent
3542
from .beta_tool_result_block_param import BetaToolResultBlockParam as BetaToolResultBlockParam
3643
from .beta_raw_message_stream_event import BetaRawMessageStreamEvent as BetaRawMessageStreamEvent
3744
from .beta_tool_bash_20241022_param import BetaToolBash20241022Param as BetaToolBash20241022Param
45+
from .beta_content_block_source_param import BetaContentBlockSourceParam as BetaContentBlockSourceParam
46+
from .beta_citation_char_location_param import BetaCitationCharLocationParam as BetaCitationCharLocationParam
47+
from .beta_citation_page_location_param import BetaCitationPageLocationParam as BetaCitationPageLocationParam
3848
from .beta_raw_content_block_stop_event import BetaRawContentBlockStopEvent as BetaRawContentBlockStopEvent
3949
from .beta_cache_control_ephemeral_param import BetaCacheControlEphemeralParam as BetaCacheControlEphemeralParam
4050
from .beta_raw_content_block_delta_event import BetaRawContentBlockDeltaEvent as BetaRawContentBlockDeltaEvent
4151
from .beta_raw_content_block_start_event import BetaRawContentBlockStartEvent as BetaRawContentBlockStartEvent
52+
from .beta_citation_content_block_location import BetaCitationContentBlockLocation as BetaCitationContentBlockLocation
4253
from .beta_tool_text_editor_20241022_param import BetaToolTextEditor20241022Param as BetaToolTextEditor20241022Param
4354
from .beta_tool_computer_use_20241022_param import BetaToolComputerUse20241022Param as BetaToolComputerUse20241022Param
55+
from .beta_content_block_source_content_param import (
56+
BetaContentBlockSourceContentParam as BetaContentBlockSourceContentParam,
57+
)
58+
from .beta_citation_content_block_location_param import (
59+
BetaCitationContentBlockLocationParam as BetaCitationContentBlockLocationParam,
60+
)

src/anthropic/types/beta/beta_base64_pdf_block_param.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22

33
from __future__ import annotations
44

5-
from typing import Optional
6-
from typing_extensions import Literal, Required, TypedDict
5+
from typing import Union, Optional
6+
from typing_extensions import Literal, Required, TypeAlias, TypedDict
77

8+
from .beta_citations_config_param import BetaCitationsConfigParam
89
from .beta_base64_pdf_source_param import BetaBase64PDFSourceParam
10+
from .beta_plain_text_source_param import BetaPlainTextSourceParam
11+
from .beta_content_block_source_param import BetaContentBlockSourceParam
912
from .beta_cache_control_ephemeral_param import BetaCacheControlEphemeralParam
1013

11-
__all__ = ["BetaBase64PDFBlockParam"]
14+
__all__ = ["BetaBase64PDFBlockParam", "Source"]
15+
16+
Source: TypeAlias = Union[BetaBase64PDFSourceParam, BetaPlainTextSourceParam, BetaContentBlockSourceParam]
1217

1318

1419
class BetaBase64PDFBlockParam(TypedDict, total=False):
15-
source: Required[BetaBase64PDFSourceParam]
20+
source: Required[Source]
1621

1722
type: Required[Literal["document"]]
1823

1924
cache_control: Optional[BetaCacheControlEphemeralParam]
25+
26+
citations: BetaCitationsConfigParam
27+
28+
context: Optional[str]
29+
30+
title: Optional[str]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Optional
4+
from typing_extensions import Literal
5+
6+
from ..._models import BaseModel
7+
8+
__all__ = ["BetaCitationCharLocation"]
9+
10+
11+
class BetaCitationCharLocation(BaseModel):
12+
cited_text: str
13+
14+
document_index: int
15+
16+
document_title: Optional[str] = None
17+
18+
end_char_index: int
19+
20+
start_char_index: int
21+
22+
type: Literal["char_location"]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing import Optional
6+
from typing_extensions import Literal, Required, TypedDict
7+
8+
__all__ = ["BetaCitationCharLocationParam"]
9+
10+
11+
class BetaCitationCharLocationParam(TypedDict, total=False):
12+
cited_text: Required[str]
13+
14+
document_index: Required[int]
15+
16+
document_title: Required[Optional[str]]
17+
18+
end_char_index: Required[int]
19+
20+
start_char_index: Required[int]
21+
22+
type: Required[Literal["char_location"]]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Optional
4+
from typing_extensions import Literal
5+
6+
from ..._models import BaseModel
7+
8+
__all__ = ["BetaCitationContentBlockLocation"]
9+
10+
11+
class BetaCitationContentBlockLocation(BaseModel):
12+
cited_text: str
13+
14+
document_index: int
15+
16+
document_title: Optional[str] = None
17+
18+
end_block_index: int
19+
20+
start_block_index: int
21+
22+
type: Literal["content_block_location"]

0 commit comments

Comments
 (0)