get_final_text() — anthropic-sdk-python Function Reference
Architecture documentation for the get_final_text() function in _messages.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 85eb3149_498e_f553_00e0_c28342315541["get_final_text()"] 4f4cec09_94d5_eeb6_5c17_29d2af98f435["AsyncMessageStream"] 85eb3149_498e_f553_00e0_c28342315541 -->|defined in| 4f4cec09_94d5_eeb6_5c17_29d2af98f435 1bc68915_5733_1542_a79b_791f2a5ac05e["get_final_text()"] 1bc68915_5733_1542_a79b_791f2a5ac05e -->|calls| 85eb3149_498e_f553_00e0_c28342315541 f4a46199_2749_e343_7f26_2f26657ae526["get_final_message()"] 85eb3149_498e_f553_00e0_c28342315541 -->|calls| f4a46199_2749_e343_7f26_2f26657ae526 1bc68915_5733_1542_a79b_791f2a5ac05e["get_final_text()"] 85eb3149_498e_f553_00e0_c28342315541 -->|calls| 1bc68915_5733_1542_a79b_791f2a5ac05e style 85eb3149_498e_f553_00e0_c28342315541 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/lib/streaming/_messages.py lines 245–264
async def get_final_text(self) -> str:
"""Returns all `text` content blocks concatenated together.
> [!NOTE]
> Currently the API will only respond with a single content block.
Will raise an error if no `text` content blocks were returned.
"""
message = await self.get_final_message()
text_blocks: list[str] = []
for block in message.content:
if block.type == "text":
text_blocks.append(block.text)
if not text_blocks:
raise RuntimeError(
f".get_final_text() can only be called when the API returns a `text` content block.\nThe API returned {','.join([b.type for b in message.content])} content block type(s) that you can access by calling get_final_message().content"
)
return "".join(text_blocks)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does get_final_text() do?
get_final_text() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/lib/streaming/_messages.py.
Where is get_final_text() defined?
get_final_text() is defined in src/anthropic/lib/streaming/_messages.py at line 245.
What does get_final_text() call?
get_final_text() calls 2 function(s): get_final_message, get_final_text.
What calls get_final_text()?
get_final_text() is called by 1 function(s): get_final_text.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free