get_final_text() — anthropic-sdk-python Function Reference
Architecture documentation for the get_final_text() function in _beta_messages.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD f9a35b6c_3f14_3846_ea2f_b2a1210dd93b["get_final_text()"] 8e652b46_6f9a_daae_5db8_1aa0b9386626["BetaAsyncMessageStream"] f9a35b6c_3f14_3846_ea2f_b2a1210dd93b -->|defined in| 8e652b46_6f9a_daae_5db8_1aa0b9386626 024c5edb_9d15_f7bc_2a82_77f22e1d8838["get_final_text()"] 024c5edb_9d15_f7bc_2a82_77f22e1d8838 -->|calls| f9a35b6c_3f14_3846_ea2f_b2a1210dd93b 55b6abea_0990_ff98_54bd_a0fa130e0892["get_final_message()"] f9a35b6c_3f14_3846_ea2f_b2a1210dd93b -->|calls| 55b6abea_0990_ff98_54bd_a0fa130e0892 024c5edb_9d15_f7bc_2a82_77f22e1d8838["get_final_text()"] f9a35b6c_3f14_3846_ea2f_b2a1210dd93b -->|calls| 024c5edb_9d15_f7bc_2a82_77f22e1d8838 a493aa49_e2c3_381a_28e6_6809172e402a["get_final_message()"] f9a35b6c_3f14_3846_ea2f_b2a1210dd93b -->|calls| a493aa49_e2c3_381a_28e6_6809172e402a style f9a35b6c_3f14_3846_ea2f_b2a1210dd93b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/lib/streaming/_beta_messages.py lines 249–268
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
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/_beta_messages.py.
Where is get_final_text() defined?
get_final_text() is defined in src/anthropic/lib/streaming/_beta_messages.py at line 249.
What does get_final_text() call?
get_final_text() calls 3 function(s): get_final_message, 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