truefoundry-gateway-sdk 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. truefoundry_gateway_sdk-0.0.0/PKG-INFO +292 -0
  2. truefoundry_gateway_sdk-0.0.0/README.md +260 -0
  3. truefoundry_gateway_sdk-0.0.0/pyproject.toml +99 -0
  4. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/__init__.py +310 -0
  5. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/_default_clients.py +32 -0
  6. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/agents/__init__.py +35 -0
  7. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/agents/client.py +63 -0
  8. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/agents/raw_client.py +13 -0
  9. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/agents/responses/__init__.py +34 -0
  10. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/agents/responses/client.py +204 -0
  11. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/agents/responses/raw_client.py +466 -0
  12. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/agents/responses/types/__init__.py +34 -0
  13. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/agents/responses/types/responses_cancel_response.py +16 -0
  14. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/base_client.py +249 -0
  15. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/client.py +73 -0
  16. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/__init__.py +127 -0
  17. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/api_error.py +23 -0
  18. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/client_wrapper.py +106 -0
  19. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/datetime_utils.py +70 -0
  20. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/enum.py +20 -0
  21. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/file.py +67 -0
  22. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/force_multipart.py +18 -0
  23. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/http_client.py +839 -0
  24. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/http_response.py +59 -0
  25. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/http_sse/__init__.py +42 -0
  26. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/http_sse/_api.py +148 -0
  27. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/http_sse/_decoders.py +61 -0
  28. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/http_sse/_exceptions.py +7 -0
  29. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/http_sse/_models.py +17 -0
  30. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/jsonable_encoder.py +120 -0
  31. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/logging.py +107 -0
  32. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/parse_error.py +36 -0
  33. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/pydantic_utilities.py +634 -0
  34. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/query_encoder.py +58 -0
  35. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/remove_none_from_dict.py +11 -0
  36. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/request_options.py +35 -0
  37. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/core/serialization.py +276 -0
  38. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/environment.py +7 -0
  39. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/errors/__init__.py +56 -0
  40. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/errors/bad_request_error.py +11 -0
  41. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/errors/failed_dependency_error.py +10 -0
  42. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/errors/forbidden_error.py +11 -0
  43. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/errors/internal_server_error.py +11 -0
  44. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/errors/not_found_error.py +11 -0
  45. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/errors/precondition_failed_error.py +10 -0
  46. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/errors/unauthorized_error.py +11 -0
  47. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/py.typed +0 -0
  48. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/__init__.py +266 -0
  49. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_approval_decision.py +8 -0
  50. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_approval_decision_message.py +22 -0
  51. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_approval_decision_reason.py +19 -0
  52. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_approval_decision_zero.py +18 -0
  53. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_approval_or_tool_response_message.py +8 -0
  54. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_approval_required.py +21 -0
  55. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_assistant_message.py +23 -0
  56. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_client_side_tool_response_message.py +21 -0
  57. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_enriched_assistant_message.py +30 -0
  58. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_enriched_assistant_message_audio.py +18 -0
  59. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_enriched_assistant_message_content.py +7 -0
  60. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_enriched_assistant_message_content_one_item.py +10 -0
  61. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_enriched_assistant_message_function_call.py +19 -0
  62. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_enriched_assistant_message_thinking_blocks_item.py +8 -0
  63. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_enriched_tool_call.py +20 -0
  64. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_execution_created.py +24 -0
  65. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_execution_done.py +23 -0
  66. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_execution_error.py +24 -0
  67. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_extended_delta.py +28 -0
  68. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_extended_delta_function_call.py +19 -0
  69. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_extended_delta_role.py +46 -0
  70. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_extended_delta_thinking_blocks_item.py +8 -0
  71. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_extended_delta_tool_call.py +21 -0
  72. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_file_upload_content_part.py +20 -0
  73. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_file_upload_content_part_file.py +22 -0
  74. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_finish_reason.py +46 -0
  75. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_info.py +20 -0
  76. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_input_user_message.py +20 -0
  77. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_input_user_message_content.py +7 -0
  78. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_input_user_message_content_one_item.py +8 -0
  79. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_llm_message_delta.py +23 -0
  80. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_llm_tool_message.py +20 -0
  81. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_mcp_auth_required.py +20 -0
  82. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_mcp_initialization_info.py +20 -0
  83. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_mcp_initialize.py +21 -0
  84. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_mcp_server_auth_info.py +21 -0
  85. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_mcp_server_request.py +23 -0
  86. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_mcp_tool.py +19 -0
  87. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_mcp_tool_call_info.py +23 -0
  88. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_model_params.py +24 -0
  89. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_model_params_reasoning_effort.py +46 -0
  90. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_parent.py +19 -0
  91. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_raw_tool_call.py +19 -0
  92. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_redacted_thinking_block.py +19 -0
  93. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_response_created.py +20 -0
  94. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_response_done.py +9 -0
  95. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_response_done_cancelled.py +21 -0
  96. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_response_done_cancelled_cancellation_reason.py +34 -0
  97. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_response_done_completed.py +19 -0
  98. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_response_done_error.py +22 -0
  99. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_response_streaming_output_event.py +31 -0
  100. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_body.py +8 -0
  101. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_format.py +9 -0
  102. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_format_json_schema.py +20 -0
  103. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_format_json_schema_json_schema.py +25 -0
  104. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_format_one.py +18 -0
  105. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_format_zero.py +18 -0
  106. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_inline_agent.py +40 -0
  107. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_inline_agent_messages_item.py +19 -0
  108. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_inline_agent_sandbox.py +18 -0
  109. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_named_agent.py +26 -0
  110. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_responses_stateful_input.py +10 -0
  111. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_sandbox_created.py +19 -0
  112. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_skill_mount.py +26 -0
  113. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_text_content_part.py +19 -0
  114. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_thinking_block.py +20 -0
  115. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_tool_call_ref.py +18 -0
  116. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_tool_message.py +21 -0
  117. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/agent_tool_response_required.py +21 -0
  118. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/chat_completion_chunk_delta_tool_call.py +22 -0
  119. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/chat_completion_chunk_delta_tool_call_function.py +19 -0
  120. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/chat_completion_content_part_refusal.py +19 -0
  121. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/chat_completion_content_part_text.py +19 -0
  122. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/chat_completion_message_tool_call.py +21 -0
  123. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/chat_completion_message_tool_call_function.py +19 -0
  124. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/request_error_response.py +19 -0
  125. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/types/request_error_response_error.py +21 -0
  126. truefoundry_gateway_sdk-0.0.0/src/truefoundry_gateway_sdk/version.py +3 -0
@@ -0,0 +1,292 @@
1
+ Metadata-Version: 2.1
2
+ Name: truefoundry-gateway-sdk
3
+ Version: 0.0.0
4
+ Summary:
5
+ Requires-Python: >=3.10,<4.0
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: Operating System :: MacOS
8
+ Classifier: Operating System :: Microsoft :: Windows
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Operating System :: POSIX
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: 3.15
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Provides-Extra: aiohttp
23
+ Requires-Dist: aiohttp (>=3.13.4,<4) ; (python_version >= "3.9") and (extra == "aiohttp")
24
+ Requires-Dist: httpx (>=0.21.2)
25
+ Requires-Dist: httpx-aiohttp (==0.1.8) ; (python_version >= "3.9") and (extra == "aiohttp")
26
+ Requires-Dist: pydantic (>=1.9.2)
27
+ Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
28
+ Requires-Dist: typing_extensions (>=4.0.0)
29
+ Project-URL: Repository, https://github.com/truefoundry/truefoundry-gateway-python-sdk
30
+ Description-Content-Type: text/markdown
31
+
32
+ # Truefoundry Python Library
33
+
34
+ [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Ftruefoundry%2Ftruefoundry-gateway-python-sdk)
35
+ [![pypi](https://img.shields.io/pypi/v/truefoundry-gateway-sdk)](https://pypi.python.org/pypi/truefoundry-gateway-sdk)
36
+
37
+ This library provides convenient access to the TrueFoundry Gateway agent API. The gateway is a stateful, multi-tenant runtime that streams agent responses over Server-Sent Events.
38
+
39
+ Call the gateway directly — not via the control-plane `/api/llm` proxy. The tenant name is part of the base URL (e.g. `https://gateway.truefoundry.ai/<tenant>`) and is applied to every request.
40
+
41
+ > [!tip]
42
+ > You can ask questions about this SDK using DeepWiki
43
+ > - Python: [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/truefoundry/truefoundry-gateway-python-sdk)
44
+ > - TypeScript: [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/truefoundry/truefoundry-gateway-typescript-sdk)
45
+
46
+
47
+ ## Table of Contents
48
+
49
+ - [Install](#install)
50
+ - [Quickstart](#quickstart)
51
+ - [Releasing](#releasing)
52
+ - [Installation](#installation)
53
+ - [Reference](#reference)
54
+ - [Usage](#usage)
55
+ - [Environments](#environments)
56
+ - [Async Client](#async-client)
57
+ - [Exception Handling](#exception-handling)
58
+ - [Streaming](#streaming)
59
+ - [Advanced](#advanced)
60
+ - [Access Raw Response Data](#access-raw-response-data)
61
+ - [Retries](#retries)
62
+ - [Timeouts](#timeouts)
63
+ - [Custom Client](#custom-client)
64
+ - [Contributing](#contributing)
65
+
66
+ ## Install
67
+
68
+ ```sh
69
+ pip install truefoundry-gateway-sdk
70
+ ```
71
+
72
+ ## Quickstart
73
+
74
+ ```python
75
+ from truefoundry_gateway_sdk import (
76
+ AgentInputUserMessage,
77
+ NamedAgentRunInput,
78
+ TruefoundryGateway,
79
+ )
80
+
81
+ client = TruefoundryGateway(
82
+ base_url="https://gateway.truefoundry.ai/<tenant>",
83
+ token="<TFY_API_KEY>",
84
+ )
85
+
86
+ for event in client.agent.responses.create(
87
+ request=NamedAgentRunInput(
88
+ agent_name="my-agent",
89
+ input=[AgentInputUserMessage(role="user", content="hi")],
90
+ ),
91
+ ):
92
+ print(event)
93
+ ```
94
+
95
+ `AsyncTruefoundryGateway` provides the same surface with `async`/`await`.
96
+
97
+ ## Releasing
98
+
99
+ Releases are cut from
100
+ [`truefoundry/truefoundry-gateway-fern-config`](https://github.com/truefoundry/truefoundry-gateway-fern-config)
101
+ by pushing a `v*` tag there. The Fern workflow regenerates this repo onto a
102
+ `release-v<version>` branch and publishes the wheel to PyPI in the same job.
103
+
104
+ ## Installation
105
+
106
+ ```sh
107
+ pip install truefoundry-gateway-sdk
108
+ ```
109
+
110
+ ## Reference
111
+
112
+ A full reference for this library is available [here](https://github.com/truefoundry/truefoundry-gateway-python-sdk/blob/HEAD/./reference.md).
113
+
114
+ ## Usage
115
+
116
+ Instantiate and use the client with the following:
117
+
118
+ ```python
119
+ from truefoundry_gateway_sdk import TruefoundryGateway, AgentResponsesInlineAgent
120
+
121
+ client = TruefoundryGateway(
122
+ token="<token>",
123
+ )
124
+
125
+ client.agents.responses.create(
126
+ request=AgentResponsesInlineAgent(
127
+ model="model",
128
+ ),
129
+ )
130
+ ```
131
+
132
+ ## Environments
133
+
134
+ This SDK allows you to configure different environments for API requests.
135
+
136
+ ```python
137
+ from truefoundry_gateway_sdk import TruefoundryGateway
138
+ from truefoundry_gateway_sdk.environment import TruefoundryGatewayEnvironment
139
+
140
+ client = TruefoundryGateway(
141
+ environment=TruefoundryGatewayEnvironment.DEFAULT,
142
+ )
143
+ ```
144
+
145
+ ## Async Client
146
+
147
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use `httpx.AsyncClient()` instead of `httpx.Client()` (e.g. for the `httpx_client` parameter of this client).
148
+
149
+ ```python
150
+ import asyncio
151
+
152
+ from truefoundry_gateway_sdk import AsyncTruefoundryGateway
153
+
154
+ client = AsyncTruefoundryGateway(
155
+ token="<token>",
156
+ )
157
+
158
+
159
+ async def main() -> None:
160
+ await client.agents.responses.create(
161
+ request=AgentResponsesInlineAgent(
162
+ model="model",
163
+ ),
164
+ )
165
+
166
+
167
+ asyncio.run(main())
168
+ ```
169
+
170
+ ## Exception Handling
171
+
172
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
173
+ will be thrown.
174
+
175
+ ```python
176
+ from truefoundry_gateway_sdk.core.api_error import ApiError
177
+
178
+ try:
179
+ client.agents.responses.create(...)
180
+ except ApiError as e:
181
+ print(e.status_code)
182
+ print(e.body)
183
+ ```
184
+
185
+ ## Streaming
186
+
187
+ The SDK supports streaming responses, as well, the response will be a generator that you can loop over.
188
+
189
+ ```python
190
+ from truefoundry_gateway_sdk import TruefoundryGateway, AgentResponsesInlineAgent
191
+
192
+ client = TruefoundryGateway(
193
+ token="<token>",
194
+ )
195
+
196
+ client.agents.responses.create(
197
+ request=AgentResponsesInlineAgent(
198
+ model="model",
199
+ ),
200
+ )
201
+ ```
202
+
203
+ ## Advanced
204
+
205
+ ### Access Raw Response Data
206
+
207
+ The SDK provides access to raw response data, including headers, through the `.with_raw_response` property.
208
+ The `.with_raw_response` property returns a "raw" client that can be used to access the `.headers` and `.data` attributes.
209
+
210
+ ```python
211
+ from truefoundry_gateway_sdk import TruefoundryGateway
212
+
213
+ client = TruefoundryGateway(...)
214
+ response = client.agents.responses.with_raw_response.create(...)
215
+ print(response.headers) # access the response headers
216
+ print(response.status_code) # access the response status code
217
+ print(response.data) # access the underlying object
218
+ ```
219
+
220
+ ### Retries
221
+
222
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
223
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
224
+ retry limit (default: 2).
225
+
226
+ Which status codes are retried depends on the `retryStatusCodes` generator configuration:
227
+
228
+ **`legacy`** (current default): retries on
229
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
230
+ - [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
231
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
232
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (All server errors, including 500)
233
+
234
+ **`recommended`**: retries on
235
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
236
+ - [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
237
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
238
+ - [502](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502) (Bad Gateway)
239
+ - [503](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) (Service Unavailable)
240
+ - [504](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504) (Gateway Timeout)
241
+
242
+ Use the `max_retries` request option to configure this behavior.
243
+
244
+ ```python
245
+ client.agents.responses.create(..., request_options={
246
+ "max_retries": 1
247
+ })
248
+ ```
249
+
250
+ ### Timeouts
251
+
252
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
253
+
254
+ ```python
255
+ from truefoundry_gateway_sdk import TruefoundryGateway
256
+
257
+ client = TruefoundryGateway(..., timeout=20.0)
258
+
259
+ # Override timeout for a specific method
260
+ client.agents.responses.create(..., request_options={
261
+ "timeout_in_seconds": 1
262
+ })
263
+ ```
264
+
265
+ ### Custom Client
266
+
267
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
268
+ and transports.
269
+
270
+ ```python
271
+ import httpx
272
+ from truefoundry_gateway_sdk import TruefoundryGateway
273
+
274
+ client = TruefoundryGateway(
275
+ ...,
276
+ httpx_client=httpx.Client(
277
+ proxy="http://my.test.proxy.example.com",
278
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
279
+ ),
280
+ )
281
+ ```
282
+
283
+ ## Contributing
284
+
285
+ While we value open-source contributions to this SDK, this library is generated programmatically.
286
+ Additions made directly to this library would have to be moved over to our generation code,
287
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
288
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
289
+ an issue first to discuss with us!
290
+
291
+ On the other hand, contributions to the README are always very welcome!
292
+
@@ -0,0 +1,260 @@
1
+ # Truefoundry Python Library
2
+
3
+ [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Ftruefoundry%2Ftruefoundry-gateway-python-sdk)
4
+ [![pypi](https://img.shields.io/pypi/v/truefoundry-gateway-sdk)](https://pypi.python.org/pypi/truefoundry-gateway-sdk)
5
+
6
+ This library provides convenient access to the TrueFoundry Gateway agent API. The gateway is a stateful, multi-tenant runtime that streams agent responses over Server-Sent Events.
7
+
8
+ Call the gateway directly — not via the control-plane `/api/llm` proxy. The tenant name is part of the base URL (e.g. `https://gateway.truefoundry.ai/<tenant>`) and is applied to every request.
9
+
10
+ > [!tip]
11
+ > You can ask questions about this SDK using DeepWiki
12
+ > - Python: [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/truefoundry/truefoundry-gateway-python-sdk)
13
+ > - TypeScript: [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/truefoundry/truefoundry-gateway-typescript-sdk)
14
+
15
+
16
+ ## Table of Contents
17
+
18
+ - [Install](#install)
19
+ - [Quickstart](#quickstart)
20
+ - [Releasing](#releasing)
21
+ - [Installation](#installation)
22
+ - [Reference](#reference)
23
+ - [Usage](#usage)
24
+ - [Environments](#environments)
25
+ - [Async Client](#async-client)
26
+ - [Exception Handling](#exception-handling)
27
+ - [Streaming](#streaming)
28
+ - [Advanced](#advanced)
29
+ - [Access Raw Response Data](#access-raw-response-data)
30
+ - [Retries](#retries)
31
+ - [Timeouts](#timeouts)
32
+ - [Custom Client](#custom-client)
33
+ - [Contributing](#contributing)
34
+
35
+ ## Install
36
+
37
+ ```sh
38
+ pip install truefoundry-gateway-sdk
39
+ ```
40
+
41
+ ## Quickstart
42
+
43
+ ```python
44
+ from truefoundry_gateway_sdk import (
45
+ AgentInputUserMessage,
46
+ NamedAgentRunInput,
47
+ TruefoundryGateway,
48
+ )
49
+
50
+ client = TruefoundryGateway(
51
+ base_url="https://gateway.truefoundry.ai/<tenant>",
52
+ token="<TFY_API_KEY>",
53
+ )
54
+
55
+ for event in client.agent.responses.create(
56
+ request=NamedAgentRunInput(
57
+ agent_name="my-agent",
58
+ input=[AgentInputUserMessage(role="user", content="hi")],
59
+ ),
60
+ ):
61
+ print(event)
62
+ ```
63
+
64
+ `AsyncTruefoundryGateway` provides the same surface with `async`/`await`.
65
+
66
+ ## Releasing
67
+
68
+ Releases are cut from
69
+ [`truefoundry/truefoundry-gateway-fern-config`](https://github.com/truefoundry/truefoundry-gateway-fern-config)
70
+ by pushing a `v*` tag there. The Fern workflow regenerates this repo onto a
71
+ `release-v<version>` branch and publishes the wheel to PyPI in the same job.
72
+
73
+ ## Installation
74
+
75
+ ```sh
76
+ pip install truefoundry-gateway-sdk
77
+ ```
78
+
79
+ ## Reference
80
+
81
+ A full reference for this library is available [here](https://github.com/truefoundry/truefoundry-gateway-python-sdk/blob/HEAD/./reference.md).
82
+
83
+ ## Usage
84
+
85
+ Instantiate and use the client with the following:
86
+
87
+ ```python
88
+ from truefoundry_gateway_sdk import TruefoundryGateway, AgentResponsesInlineAgent
89
+
90
+ client = TruefoundryGateway(
91
+ token="<token>",
92
+ )
93
+
94
+ client.agents.responses.create(
95
+ request=AgentResponsesInlineAgent(
96
+ model="model",
97
+ ),
98
+ )
99
+ ```
100
+
101
+ ## Environments
102
+
103
+ This SDK allows you to configure different environments for API requests.
104
+
105
+ ```python
106
+ from truefoundry_gateway_sdk import TruefoundryGateway
107
+ from truefoundry_gateway_sdk.environment import TruefoundryGatewayEnvironment
108
+
109
+ client = TruefoundryGateway(
110
+ environment=TruefoundryGatewayEnvironment.DEFAULT,
111
+ )
112
+ ```
113
+
114
+ ## Async Client
115
+
116
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use `httpx.AsyncClient()` instead of `httpx.Client()` (e.g. for the `httpx_client` parameter of this client).
117
+
118
+ ```python
119
+ import asyncio
120
+
121
+ from truefoundry_gateway_sdk import AsyncTruefoundryGateway
122
+
123
+ client = AsyncTruefoundryGateway(
124
+ token="<token>",
125
+ )
126
+
127
+
128
+ async def main() -> None:
129
+ await client.agents.responses.create(
130
+ request=AgentResponsesInlineAgent(
131
+ model="model",
132
+ ),
133
+ )
134
+
135
+
136
+ asyncio.run(main())
137
+ ```
138
+
139
+ ## Exception Handling
140
+
141
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
142
+ will be thrown.
143
+
144
+ ```python
145
+ from truefoundry_gateway_sdk.core.api_error import ApiError
146
+
147
+ try:
148
+ client.agents.responses.create(...)
149
+ except ApiError as e:
150
+ print(e.status_code)
151
+ print(e.body)
152
+ ```
153
+
154
+ ## Streaming
155
+
156
+ The SDK supports streaming responses, as well, the response will be a generator that you can loop over.
157
+
158
+ ```python
159
+ from truefoundry_gateway_sdk import TruefoundryGateway, AgentResponsesInlineAgent
160
+
161
+ client = TruefoundryGateway(
162
+ token="<token>",
163
+ )
164
+
165
+ client.agents.responses.create(
166
+ request=AgentResponsesInlineAgent(
167
+ model="model",
168
+ ),
169
+ )
170
+ ```
171
+
172
+ ## Advanced
173
+
174
+ ### Access Raw Response Data
175
+
176
+ The SDK provides access to raw response data, including headers, through the `.with_raw_response` property.
177
+ The `.with_raw_response` property returns a "raw" client that can be used to access the `.headers` and `.data` attributes.
178
+
179
+ ```python
180
+ from truefoundry_gateway_sdk import TruefoundryGateway
181
+
182
+ client = TruefoundryGateway(...)
183
+ response = client.agents.responses.with_raw_response.create(...)
184
+ print(response.headers) # access the response headers
185
+ print(response.status_code) # access the response status code
186
+ print(response.data) # access the underlying object
187
+ ```
188
+
189
+ ### Retries
190
+
191
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
192
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
193
+ retry limit (default: 2).
194
+
195
+ Which status codes are retried depends on the `retryStatusCodes` generator configuration:
196
+
197
+ **`legacy`** (current default): retries on
198
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
199
+ - [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
200
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
201
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (All server errors, including 500)
202
+
203
+ **`recommended`**: retries on
204
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
205
+ - [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
206
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
207
+ - [502](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502) (Bad Gateway)
208
+ - [503](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) (Service Unavailable)
209
+ - [504](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504) (Gateway Timeout)
210
+
211
+ Use the `max_retries` request option to configure this behavior.
212
+
213
+ ```python
214
+ client.agents.responses.create(..., request_options={
215
+ "max_retries": 1
216
+ })
217
+ ```
218
+
219
+ ### Timeouts
220
+
221
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
222
+
223
+ ```python
224
+ from truefoundry_gateway_sdk import TruefoundryGateway
225
+
226
+ client = TruefoundryGateway(..., timeout=20.0)
227
+
228
+ # Override timeout for a specific method
229
+ client.agents.responses.create(..., request_options={
230
+ "timeout_in_seconds": 1
231
+ })
232
+ ```
233
+
234
+ ### Custom Client
235
+
236
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
237
+ and transports.
238
+
239
+ ```python
240
+ import httpx
241
+ from truefoundry_gateway_sdk import TruefoundryGateway
242
+
243
+ client = TruefoundryGateway(
244
+ ...,
245
+ httpx_client=httpx.Client(
246
+ proxy="http://my.test.proxy.example.com",
247
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
248
+ ),
249
+ )
250
+ ```
251
+
252
+ ## Contributing
253
+
254
+ While we value open-source contributions to this SDK, this library is generated programmatically.
255
+ Additions made directly to this library would have to be moved over to our generation code,
256
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
257
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
258
+ an issue first to discuss with us!
259
+
260
+ On the other hand, contributions to the README are always very welcome!
@@ -0,0 +1,99 @@
1
+ [project]
2
+ name = "truefoundry-gateway-sdk"
3
+ dynamic = ["version"]
4
+
5
+ [tool.poetry]
6
+ name = "truefoundry-gateway-sdk"
7
+ version = "0.0.0"
8
+ description = ""
9
+ readme = "README.md"
10
+ authors = []
11
+ keywords = []
12
+
13
+ classifiers = [
14
+ "Intended Audience :: Developers",
15
+ "Programming Language :: Python",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.10",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Programming Language :: Python :: 3.14",
22
+ "Programming Language :: Python :: 3.15",
23
+ "Operating System :: OS Independent",
24
+ "Operating System :: POSIX",
25
+ "Operating System :: MacOS",
26
+ "Operating System :: POSIX :: Linux",
27
+ "Operating System :: Microsoft :: Windows",
28
+ "Topic :: Software Development :: Libraries :: Python Modules",
29
+ "Typing :: Typed"
30
+ ]
31
+ packages = [
32
+ { include = "truefoundry_gateway_sdk", from = "src"}
33
+ ]
34
+
35
+ [tool.poetry.urls]
36
+ Repository = 'https://github.com/truefoundry/truefoundry-gateway-python-sdk'
37
+
38
+ [tool.poetry.dependencies]
39
+ python = "^3.10"
40
+ aiohttp = { version = ">=3.13.4,<4", optional = true, python = ">=3.9"}
41
+ httpx = ">=0.21.2"
42
+ httpx-aiohttp = { version = "0.1.8", optional = true, python = ">=3.9"}
43
+ pydantic = ">= 1.9.2"
44
+ pydantic-core = ">=2.18.2,<3.0.0"
45
+ typing_extensions = ">= 4.0.0"
46
+
47
+ [tool.poetry.group.dev.dependencies]
48
+ mypy = "==1.13.0"
49
+ pytest = "^9.0.3"
50
+ pytest-asyncio = "^1.0.0"
51
+ pytest-xdist = "^3.6.1"
52
+ python-dateutil = "^2.9.0"
53
+ types-python-dateutil = "^2.9.0.20240316"
54
+ urllib3 = ">=2.6.3,<3.0.0"
55
+ Jinja2 = ">=3.1.6,<4.0.0"
56
+ ipython = ">=8.0.0,<10.0.0"
57
+ numpydoc = ">=1.7.0,<2.0.0"
58
+ ruff = "==0.11.5"
59
+
60
+ [tool.pytest.ini_options]
61
+ testpaths = [ "tests" ]
62
+ asyncio_mode = "auto"
63
+ markers = [
64
+ "aiohttp: tests that require httpx_aiohttp to be installed",
65
+ ]
66
+
67
+ [tool.mypy]
68
+ plugins = ["pydantic.mypy"]
69
+
70
+ [tool.ruff]
71
+ line-length = 120
72
+
73
+ [tool.ruff.lint]
74
+ select = [
75
+ "E", # pycodestyle errors
76
+ "F", # pyflakes
77
+ "I", # isort
78
+ ]
79
+ ignore = [
80
+ "E402", # Module level import not at top of file
81
+ "E501", # Line too long
82
+ "E711", # Comparison to `None` should be `cond is not None`
83
+ "E712", # Avoid equality comparisons to `True`; use `if ...:` checks
84
+ "E721", # Use `is` and `is not` for type comparisons, or `isinstance()` for insinstance checks
85
+ "E722", # Do not use bare `except`
86
+ "E731", # Do not assign a `lambda` expression, use a `def`
87
+ "F821", # Undefined name
88
+ "F841" # Local variable ... is assigned to but never used
89
+ ]
90
+
91
+ [tool.ruff.lint.isort]
92
+ section-order = ["future", "standard-library", "third-party", "first-party"]
93
+
94
+ [build-system]
95
+ requires = ["poetry-core"]
96
+ build-backend = "poetry.core.masonry.api"
97
+
98
+ [tool.poetry.extras]
99
+ aiohttp=["aiohttp", "httpx-aiohttp"]