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 024c5edb_9d15_f7bc_2a82_77f22e1d8838["get_final_text()"] fa27ef0f_31e3_cd5e_ffa3_12becd4b426b["BetaMessageStream"] 024c5edb_9d15_f7bc_2a82_77f22e1d8838 -->|defined in| fa27ef0f_31e3_cd5e_ffa3_12becd4b426b f9a35b6c_3f14_3846_ea2f_b2a1210dd93b["get_final_text()"] f9a35b6c_3f14_3846_ea2f_b2a1210dd93b -->|calls| 024c5edb_9d15_f7bc_2a82_77f22e1d8838 a493aa49_e2c3_381a_28e6_6809172e402a["get_final_message()"] 024c5edb_9d15_f7bc_2a82_77f22e1d8838 -->|calls| a493aa49_e2c3_381a_28e6_6809172e402a f9a35b6c_3f14_3846_ea2f_b2a1210dd93b["get_final_text()"] 024c5edb_9d15_f7bc_2a82_77f22e1d8838 -->|calls| f9a35b6c_3f14_3846_ea2f_b2a1210dd93b style 024c5edb_9d15_f7bc_2a82_77f22e1d8838 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/lib/streaming/_beta_messages.py lines 100–119
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 = 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 100.
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