llm-api-adapter-xai 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sergey Inozemtsev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ include README.md
2
+ include LICENSE
3
+ include src/llm_api_adapter_xai/py.typed
4
+ recursive-include src/llm_api_adapter_xai/registry/organizations *.json
5
+
6
+ global-exclude *.py[cod]
7
+ prune **/__pycache__
8
+ prune **/.pytest_cache
9
+ global-exclude *.egg-info
10
+ prune **/*.egg-info
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.4
2
+ Name: llm-api-adapter-xai
3
+ Version: 0.1.0
4
+ Summary: Official xAI Responses API package for llm-api-adapter
5
+ Author: Sergey Inozemtsev
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Sergey Inozemtsev
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Repository, https://github.com/Inozem/llm_api_adapter/
29
+ Keywords: llm,xai,grok,adapter,api
30
+ Classifier: Programming Language :: Python :: 3
31
+ Classifier: Programming Language :: Python :: 3.10
32
+ Classifier: Programming Language :: Python :: 3.11
33
+ Classifier: Programming Language :: Python :: 3.12
34
+ Classifier: Programming Language :: Python :: 3.13
35
+ Classifier: Programming Language :: Python :: 3.14
36
+ Classifier: Typing :: Typed
37
+ Classifier: License :: OSI Approved :: MIT License
38
+ Classifier: Operating System :: OS Independent
39
+ Requires-Python: >=3.10
40
+ Description-Content-Type: text/markdown
41
+ License-File: LICENSE
42
+ Requires-Dist: llm-api-adapter<1.0.0,>=0.9.1
43
+ Provides-Extra: async
44
+ Requires-Dist: llm-api-adapter[async]<1.0.0,>=0.9.1; extra == "async"
45
+ Provides-Extra: httpx
46
+ Requires-Dist: llm-api-adapter[httpx]<1.0.0,>=0.9.1; extra == "httpx"
47
+ Dynamic: license-file
48
+
49
+ # llm-api-adapter-xai
50
+
51
+ Official xAI Responses API support for
52
+ [llm-api-adapter](https://github.com/Inozem/llm_api_adapter/).
53
+
54
+ ## Installation
55
+
56
+ Install through the core package extra:
57
+
58
+ ```bash
59
+ pip install "llm-api-adapter[xai]"
60
+ ```
61
+
62
+ Direct installation is also supported when the core package is managed
63
+ separately:
64
+
65
+ ```bash
66
+ pip install llm-api-adapter-xai
67
+ ```
68
+
69
+ Async methods need HTTPX:
70
+
71
+ ```bash
72
+ pip install "llm-api-adapter[xai,async]"
73
+ ```
74
+
75
+ Synchronous `requests` remains the default. To opt into the HTTPX synchronous
76
+ transport, install `"llm-api-adapter[xai,httpx]"` and pass
77
+ `transport="httpx"`.
78
+
79
+ ## Quick start
80
+
81
+ ```python
82
+ import os
83
+
84
+ from llm_api_adapter.models.messages.chat_message import UserMessage
85
+ from llm_api_adapter.universal_adapter import UniversalLLMAPIAdapter
86
+
87
+ adapter = UniversalLLMAPIAdapter(
88
+ organization="xai",
89
+ model="grok-4.6",
90
+ api_key=os.environ["XAI_API_KEY"],
91
+ )
92
+
93
+ response = adapter.chat(
94
+ messages=[UserMessage("Explain retrieval-augmented generation.")]
95
+ )
96
+ print(response.content)
97
+ ```
98
+
99
+ ## Supported models and capabilities
100
+
101
+ The package deliberately exposes fixed model IDs, not moving aliases:
102
+ `grok-4.5` and `grok-4.6`.
103
+
104
+ | Capability | Supported models |
105
+ | --- | --- |
106
+ | Text chat, sync/async streaming, application function tools, JSON Schema/Pydantic output, image URLs or bytes, and PDF URLs or bytes | Both models |
107
+ | `reasoning_level` | `grok-4.5`: `low`–`high`; `grok-4.6`: `low`–`xhigh` |
108
+
109
+ For `grok-4.5` and `grok-4.6`, xAI cannot disable reasoning: a requested
110
+ `"none"` is mapped to the documented minimum and produces a warning.
111
+
112
+ The JSON Schema subset is limited by xAI. The adapter rejects unsupported
113
+ schemas before sending a request. See xAI's
114
+ [structured-output documentation](https://docs.x.ai/developers/model-capabilities/text/structured-outputs)
115
+ for the supported schema vocabulary.
116
+
117
+ ## Conversations, files, and costs
118
+
119
+ `previous_response` is accepted for the shared API, but xAI continuation is
120
+ intentionally not used: the adapter does not send `previous_response_id`.
121
+ Keep and provide the complete `messages` history for each turn, including
122
+ assistant tool calls and `ToolMessage` results.
123
+
124
+ The package does not expose or send xAI's `store` option. xAI documents that
125
+ Responses are stored server-side by default, so configure data retention with
126
+ xAI when that matters to your application. In particular, the library does not
127
+ turn on Zero Data Retention (ZDR); enabling ZDR in the xAI Console blocks new
128
+ Files API uploads and `file_id` attachments.
129
+
130
+ PDF URLs are passed to xAI unchanged. For PDF bytes, the adapter uploads a
131
+ provider-owned file with a 24-hour expiry; it never deletes or changes a URL or
132
+ file identifier supplied by your application. No OCR or local text extraction
133
+ is performed.
134
+
135
+ Attaching a PDF activates xAI's `attachment_search` tool. That makes the
136
+ request agentic and adds tool-invocation charges to normal token charges.
137
+ Storage for an uploaded file is also billed by xAI until it expires. Treat
138
+ `ChatResponse.cost_total` as the exact request cost only when xAI returns it;
139
+ consult xAI billing for storage and any charges not included in that response.
140
+
141
+ See the official xAI documentation for
142
+ [Responses storage](https://docs.x.ai/developers/model-capabilities/text/comparison),
143
+ [files and expiry](https://docs.x.ai/developers/files/managing-files), and
144
+ [file-search pricing](https://docs.x.ai/developers/pricing).
145
+
146
+ See the main [llm-api-adapter README](https://github.com/Inozem/llm_api_adapter/#readme)
147
+ for the shared API contract and examples.
@@ -0,0 +1,99 @@
1
+ # llm-api-adapter-xai
2
+
3
+ Official xAI Responses API support for
4
+ [llm-api-adapter](https://github.com/Inozem/llm_api_adapter/).
5
+
6
+ ## Installation
7
+
8
+ Install through the core package extra:
9
+
10
+ ```bash
11
+ pip install "llm-api-adapter[xai]"
12
+ ```
13
+
14
+ Direct installation is also supported when the core package is managed
15
+ separately:
16
+
17
+ ```bash
18
+ pip install llm-api-adapter-xai
19
+ ```
20
+
21
+ Async methods need HTTPX:
22
+
23
+ ```bash
24
+ pip install "llm-api-adapter[xai,async]"
25
+ ```
26
+
27
+ Synchronous `requests` remains the default. To opt into the HTTPX synchronous
28
+ transport, install `"llm-api-adapter[xai,httpx]"` and pass
29
+ `transport="httpx"`.
30
+
31
+ ## Quick start
32
+
33
+ ```python
34
+ import os
35
+
36
+ from llm_api_adapter.models.messages.chat_message import UserMessage
37
+ from llm_api_adapter.universal_adapter import UniversalLLMAPIAdapter
38
+
39
+ adapter = UniversalLLMAPIAdapter(
40
+ organization="xai",
41
+ model="grok-4.6",
42
+ api_key=os.environ["XAI_API_KEY"],
43
+ )
44
+
45
+ response = adapter.chat(
46
+ messages=[UserMessage("Explain retrieval-augmented generation.")]
47
+ )
48
+ print(response.content)
49
+ ```
50
+
51
+ ## Supported models and capabilities
52
+
53
+ The package deliberately exposes fixed model IDs, not moving aliases:
54
+ `grok-4.5` and `grok-4.6`.
55
+
56
+ | Capability | Supported models |
57
+ | --- | --- |
58
+ | Text chat, sync/async streaming, application function tools, JSON Schema/Pydantic output, image URLs or bytes, and PDF URLs or bytes | Both models |
59
+ | `reasoning_level` | `grok-4.5`: `low`–`high`; `grok-4.6`: `low`–`xhigh` |
60
+
61
+ For `grok-4.5` and `grok-4.6`, xAI cannot disable reasoning: a requested
62
+ `"none"` is mapped to the documented minimum and produces a warning.
63
+
64
+ The JSON Schema subset is limited by xAI. The adapter rejects unsupported
65
+ schemas before sending a request. See xAI's
66
+ [structured-output documentation](https://docs.x.ai/developers/model-capabilities/text/structured-outputs)
67
+ for the supported schema vocabulary.
68
+
69
+ ## Conversations, files, and costs
70
+
71
+ `previous_response` is accepted for the shared API, but xAI continuation is
72
+ intentionally not used: the adapter does not send `previous_response_id`.
73
+ Keep and provide the complete `messages` history for each turn, including
74
+ assistant tool calls and `ToolMessage` results.
75
+
76
+ The package does not expose or send xAI's `store` option. xAI documents that
77
+ Responses are stored server-side by default, so configure data retention with
78
+ xAI when that matters to your application. In particular, the library does not
79
+ turn on Zero Data Retention (ZDR); enabling ZDR in the xAI Console blocks new
80
+ Files API uploads and `file_id` attachments.
81
+
82
+ PDF URLs are passed to xAI unchanged. For PDF bytes, the adapter uploads a
83
+ provider-owned file with a 24-hour expiry; it never deletes or changes a URL or
84
+ file identifier supplied by your application. No OCR or local text extraction
85
+ is performed.
86
+
87
+ Attaching a PDF activates xAI's `attachment_search` tool. That makes the
88
+ request agentic and adds tool-invocation charges to normal token charges.
89
+ Storage for an uploaded file is also billed by xAI until it expires. Treat
90
+ `ChatResponse.cost_total` as the exact request cost only when xAI returns it;
91
+ consult xAI billing for storage and any charges not included in that response.
92
+
93
+ See the official xAI documentation for
94
+ [Responses storage](https://docs.x.ai/developers/model-capabilities/text/comparison),
95
+ [files and expiry](https://docs.x.ai/developers/files/managing-files), and
96
+ [file-search pricing](https://docs.x.ai/developers/pricing).
97
+
98
+ See the main [llm-api-adapter README](https://github.com/Inozem/llm_api_adapter/#readme)
99
+ for the shared API contract and examples.
@@ -0,0 +1,54 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "llm-api-adapter-xai"
7
+ version = "0.1.0"
8
+ description = "Official xAI Responses API package for llm-api-adapter"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = {file = "LICENSE"}
12
+ authors = [{name = "Sergey Inozemtsev"}]
13
+ keywords = ["llm", "xai", "grok", "adapter", "api"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.10",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
21
+ "Typing :: Typed",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Operating System :: OS Independent",
24
+ ]
25
+ dependencies = ["llm-api-adapter>=0.9.1,<1.0.0"]
26
+
27
+ [project.optional-dependencies]
28
+ async = ["llm-api-adapter[async]>=0.9.1,<1.0.0"]
29
+ httpx = ["llm-api-adapter[httpx]>=0.9.1,<1.0.0"]
30
+
31
+ [project.entry-points."llm_api_adapter.organizations"]
32
+ xai = "llm_api_adapter_xai.plugin:PLUGIN"
33
+
34
+ [project.urls]
35
+ Repository = "https://github.com/Inozem/llm_api_adapter/"
36
+
37
+ [tool.setuptools.package-dir]
38
+ "" = "src"
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["src"]
42
+ include = ["llm_api_adapter_xai*"]
43
+ exclude = ["tests*", "*/tests*"]
44
+
45
+ [tool.setuptools]
46
+ include-package-data = true
47
+
48
+ [tool.setuptools.package-data]
49
+ "llm_api_adapter_xai" = ["py.typed", "registry/organizations/*.json"]
50
+
51
+ [tool.pytest.ini_options]
52
+ markers = [
53
+ "unit: unit tests (no network, pure logic, mocks)",
54
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ """Official xAI Responses API support for :mod:`llm_api_adapter`."""
2
+
3
+ from typing import TYPE_CHECKING, Any
4
+
5
+
6
+ if TYPE_CHECKING:
7
+ from .adapter import XAIAdapter
8
+
9
+
10
+ def __getattr__(name: str) -> Any:
11
+ """Load the adapter only when the public class is requested."""
12
+ if name == "XAIAdapter":
13
+ from .adapter import XAIAdapter
14
+
15
+ return XAIAdapter
16
+ raise AttributeError(name)
17
+
18
+
19
+ __all__ = ["XAIAdapter"]