routeplane 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.
Files changed (43) hide show
  1. routeplane-0.1.0/.github/workflows/ci.yml +44 -0
  2. routeplane-0.1.0/.github/workflows/publish.yml +40 -0
  3. routeplane-0.1.0/.gitignore +13 -0
  4. routeplane-0.1.0/LICENSE +201 -0
  5. routeplane-0.1.0/PKG-INFO +278 -0
  6. routeplane-0.1.0/README.md +244 -0
  7. routeplane-0.1.0/examples/basic.py +18 -0
  8. routeplane-0.1.0/examples/crewai_integration.py +22 -0
  9. routeplane-0.1.0/examples/headers_only.py +30 -0
  10. routeplane-0.1.0/examples/langchain_integration.py +23 -0
  11. routeplane-0.1.0/examples/llamaindex_integration.py +23 -0
  12. routeplane-0.1.0/examples/metadata.py +23 -0
  13. routeplane-0.1.0/examples/resources.py +30 -0
  14. routeplane-0.1.0/examples/streaming_with_meta.py +25 -0
  15. routeplane-0.1.0/pyproject.toml +68 -0
  16. routeplane-0.1.0/src/routeplane/__init__.py +27 -0
  17. routeplane-0.1.0/src/routeplane/_streaming.py +87 -0
  18. routeplane-0.1.0/src/routeplane/_types.py +36 -0
  19. routeplane-0.1.0/src/routeplane/_version.py +1 -0
  20. routeplane-0.1.0/src/routeplane/async_client.py +173 -0
  21. routeplane-0.1.0/src/routeplane/client.py +189 -0
  22. routeplane-0.1.0/src/routeplane/headers.py +131 -0
  23. routeplane-0.1.0/src/routeplane/meta.py +75 -0
  24. routeplane-0.1.0/src/routeplane/py.typed +0 -0
  25. routeplane-0.1.0/src/routeplane/resources/__init__.py +34 -0
  26. routeplane-0.1.0/src/routeplane/resources/_base.py +112 -0
  27. routeplane-0.1.0/src/routeplane/resources/analytics.py +23 -0
  28. routeplane-0.1.0/src/routeplane/resources/cache.py +15 -0
  29. routeplane-0.1.0/src/routeplane/resources/feedback.py +24 -0
  30. routeplane-0.1.0/src/routeplane/resources/finops.py +50 -0
  31. routeplane-0.1.0/src/routeplane/resources/logs.py +19 -0
  32. routeplane-0.1.0/src/routeplane/resources/mcp.py +92 -0
  33. routeplane-0.1.0/src/routeplane/resources/models.py +28 -0
  34. routeplane-0.1.0/src/routeplane/resources/prompts.py +42 -0
  35. routeplane-0.1.0/src/routeplane/resources/providers.py +37 -0
  36. routeplane-0.1.0/src/routeplane/resources/residency.py +23 -0
  37. routeplane-0.1.0/src/routeplane/resources/status.py +25 -0
  38. routeplane-0.1.0/tests/__init__.py +0 -0
  39. routeplane-0.1.0/tests/test_client.py +117 -0
  40. routeplane-0.1.0/tests/test_headers.py +79 -0
  41. routeplane-0.1.0/tests/test_meta.py +86 -0
  42. routeplane-0.1.0/tests/test_meta_convenience.py +111 -0
  43. routeplane-0.1.0/tests/test_resources.py +339 -0
@@ -0,0 +1,44 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ concurrency:
10
+ group: ci-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ jobs:
17
+ lint:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: actions/setup-python@v5
22
+ with:
23
+ python-version: '3.12'
24
+ - run: pip install -e '.[dev]'
25
+ - name: ruff check
26
+ run: ruff check src/ tests/
27
+ - name: ruff format --check
28
+ run: ruff format --check src/ tests/
29
+ - name: mypy
30
+ run: mypy src/
31
+
32
+ test:
33
+ runs-on: ubuntu-latest
34
+ strategy:
35
+ fail-fast: false
36
+ matrix:
37
+ python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+ - uses: actions/setup-python@v5
41
+ with:
42
+ python-version: ${{ matrix.python-version }}
43
+ - run: pip install -e '.[dev]'
44
+ - run: pytest
@@ -0,0 +1,40 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags: ['v*']
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: actions/setup-python@v5
16
+ with:
17
+ python-version: '3.12'
18
+ - run: pip install build
19
+ - run: python -m build
20
+ - uses: actions/upload-artifact@v4
21
+ with:
22
+ name: dist
23
+ path: dist/
24
+
25
+ publish:
26
+ needs: build
27
+ runs-on: ubuntu-latest
28
+ environment: pypi
29
+ permissions:
30
+ id-token: write # trusted publishing (OIDC) — no token secret needed
31
+ steps:
32
+ - uses: actions/download-artifact@v4
33
+ with:
34
+ name: dist
35
+ path: dist/
36
+ - name: Publish to PyPI
37
+ uses: pypa/gh-action-pypi-publish@release/v1
38
+ # Trusted publishing: configure the PyPI project to trust
39
+ # routeplane-core/routeplane-python via the "publish" workflow +
40
+ # "pypi" environment. No PYPI_TOKEN secret required.
@@ -0,0 +1,13 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ dist/
5
+ *.egg-info/
6
+ .eggs/
7
+ .ruff_cache/
8
+ .mypy_cache/
9
+ .pytest_cache/
10
+ .env
11
+ .venv/
12
+ venv/
13
+ build/
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Routeplane
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,278 @@
1
+ Metadata-Version: 2.4
2
+ Name: routeplane
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for the Routeplane AI Gateway
5
+ Project-URL: Homepage, https://routeplane.ai
6
+ Project-URL: Documentation, https://docs.routeplane.ai
7
+ Project-URL: Repository, https://github.com/routeplane-core/routeplane-python
8
+ Project-URL: Issues, https://github.com/routeplane-core/routeplane-python/issues
9
+ Author-email: Routeplane <rp_maintainers@routeplane.ai>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: agentic-security,ai-gateway,llm,openai,proxy,routeplane
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: httpx>=0.24.0
26
+ Requires-Dist: openai>=1.0.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: mypy>=1.10; extra == 'dev'
29
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
30
+ Requires-Dist: pytest>=8.0; extra == 'dev'
31
+ Requires-Dist: respx>=0.21; extra == 'dev'
32
+ Requires-Dist: ruff>=0.5; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # Routeplane Python SDK
36
+
37
+ The official Python SDK for the [Routeplane](https://routeplane.ai) AI Gateway — a
38
+ neutral, OpenAI-compatible proxy in front of 14 LLM providers with sovereign
39
+ routing, guardrails, FinOps, and agentic security.
40
+
41
+ Routeplane speaks the OpenAI wire format, so you don't have to relearn anything.
42
+ This SDK meets you at whatever level of integration you want:
43
+
44
+ 1. **Change one line** — point the stock `openai` client at the gateway.
45
+ 2. **Add headers** — use `headers()` with *any* OpenAI-compatible client or framework.
46
+ 3. **Use the client** — `Routeplane` gives you auth, default routing, and typed
47
+ response metadata.
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install routeplane
53
+ ```
54
+
55
+ ## 1. Minimal — 30 seconds, just change `base_url`
56
+
57
+ If you already use the OpenAI SDK, point it at Routeplane and pass your gateway
58
+ key. Nothing else changes.
59
+
60
+ ```python
61
+ import openai
62
+
63
+ client = openai.OpenAI(
64
+ api_key="rp_your_gateway_key",
65
+ base_url="https://api.routeplane.ai/v1",
66
+ default_headers={"x-routeplane-api-key": "rp_your_gateway_key"},
67
+ )
68
+
69
+ resp = client.chat.completions.create(
70
+ model="gpt-4o-mini",
71
+ messages=[{"role": "user", "content": "Hello!"}],
72
+ )
73
+ print(resp.choices[0].message.content)
74
+ ```
75
+
76
+ ## 2. Intermediate — `headers()` with any client
77
+
78
+ Routeplane is configured through `x-routeplane-*` request headers (provider
79
+ routing, residency, strategy, budgets, and more). The `headers()` builder is a
80
+ typed way to produce them, and it drops into *any* client's extra-headers
81
+ escape hatch — so it works far beyond this SDK.
82
+
83
+ ```python
84
+ import openai
85
+ from routeplane import headers
86
+
87
+ client = openai.OpenAI(
88
+ api_key="rp_your_gateway_key",
89
+ base_url="https://api.routeplane.ai/v1",
90
+ default_headers={"x-routeplane-api-key": "rp_your_gateway_key"},
91
+ )
92
+
93
+ resp = client.chat.completions.create(
94
+ model="gpt-4o-mini",
95
+ messages=[{"role": "user", "content": "Summarize this contract."}],
96
+ extra_headers=headers(
97
+ provider="anthropic,openai", # fallback chain
98
+ strategy="cost", # cheapest eligible provider first
99
+ residency="IN", # keep Indian PII in-region
100
+ use_case="contract-summary", # shows up in FinOps
101
+ ),
102
+ )
103
+ ```
104
+
105
+ `headers()` only emits the options you set, JSON-serializes dict values
106
+ (`config`, `metadata`), and stringifies ints (`timeout_ms`). All 17 request
107
+ headers are typed.
108
+
109
+ ## 3. Full — the `Routeplane` client with rich metadata
110
+
111
+ `Routeplane` subclasses `openai.OpenAI`, so everything works exactly as before —
112
+ but it wires up auth for you, lets you set default routing once, and can parse
113
+ the gateway's response headers into a typed `RouteplaneMeta`.
114
+
115
+ ```python
116
+ from routeplane import Routeplane
117
+
118
+ client = Routeplane(
119
+ api_key="rp_your_gateway_key",
120
+ provider="openai,anthropic", # client-wide default fallback chain
121
+ strategy="latency",
122
+ residency="IN",
123
+ use_case="support-bot",
124
+ )
125
+
126
+ # Ordinary call — same OpenAI API you already know.
127
+ resp = client.chat.completions.create(
128
+ model="gpt-4o-mini",
129
+ messages=[{"role": "user", "content": "Hi"}],
130
+ )
131
+
132
+ # Want to know what the gateway did? Read the response headers.
133
+ raw = client.chat.completions.with_raw_response.create(
134
+ model="gpt-4o-mini",
135
+ messages=[{"role": "user", "content": "Hi"}],
136
+ )
137
+ meta = client.meta_from_headers(raw.headers)
138
+ completion = raw.parse()
139
+
140
+ print(meta.provider) # which provider actually served it
141
+ print(meta.cache) # "hit" | "miss" | "bypass"
142
+ print(meta.budget_remaining) # spend headroom
143
+ print(meta.pii_masked) # was PII masked on the way out?
144
+ ```
145
+
146
+ Per-call `extra_headers=headers(...)` still override the client defaults, so you
147
+ can set a house style once and deviate where you need to.
148
+
149
+ ### Async
150
+
151
+ ```python
152
+ from routeplane import AsyncRouteplane
153
+
154
+ client = AsyncRouteplane(api_key="rp_your_gateway_key", strategy="cost")
155
+
156
+ resp = await client.chat.completions.create(
157
+ model="gpt-4o-mini",
158
+ messages=[{"role": "user", "content": "Hello!"}],
159
+ )
160
+ ```
161
+
162
+ ## Framework examples
163
+
164
+ Because `headers()` returns a plain dict of headers, it plugs into anything that
165
+ forwards headers to the OpenAI API.
166
+
167
+ ### LangChain
168
+
169
+ ```python
170
+ from langchain_openai import ChatOpenAI
171
+ from routeplane import headers
172
+
173
+ llm = ChatOpenAI(
174
+ model="gpt-4o-mini",
175
+ api_key="rp_your_gateway_key",
176
+ base_url="https://api.routeplane.ai/v1",
177
+ default_headers={
178
+ "x-routeplane-api-key": "rp_your_gateway_key",
179
+ **headers(provider="anthropic,openai", strategy="cost"),
180
+ },
181
+ )
182
+ ```
183
+
184
+ ### LlamaIndex
185
+
186
+ ```python
187
+ from llama_index.llms.openai import OpenAI
188
+ from routeplane import headers
189
+
190
+ llm = OpenAI(
191
+ model="gpt-4o-mini",
192
+ api_key="rp_your_gateway_key",
193
+ api_base="https://api.routeplane.ai/v1",
194
+ default_headers={
195
+ "x-routeplane-api-key": "rp_your_gateway_key",
196
+ **headers(residency="IN", use_case="rag"),
197
+ },
198
+ )
199
+ ```
200
+
201
+ ### CrewAI
202
+
203
+ ```python
204
+ from crewai import LLM
205
+ from routeplane import headers
206
+
207
+ llm = LLM(
208
+ model="openai/gpt-4o-mini",
209
+ base_url="https://api.routeplane.ai/v1",
210
+ api_key="rp_your_gateway_key",
211
+ extra_headers={
212
+ "x-routeplane-api-key": "rp_your_gateway_key",
213
+ **headers(strategy="latency", use_case="research-crew"),
214
+ },
215
+ )
216
+ ```
217
+
218
+ ## Request headers reference
219
+
220
+ All are `x-routeplane-*` and all are optional except the API key. Build them with
221
+ `headers(...)`.
222
+
223
+ | Option | Header | Notes |
224
+ | --- | --- | --- |
225
+ | `provider` | `x-routeplane-provider` | Provider or comma-separated fallback chain |
226
+ | `residency` | `x-routeplane-residency` | Data-residency region (e.g. `IN`) |
227
+ | `strategy` | `x-routeplane-strategy` | `priority` \| `weighted` \| `cost` \| `latency` |
228
+ | `config` | `x-routeplane-config` | Inline routing config (JSON) |
229
+ | `timeout_ms` | `x-routeplane-timeout-ms` | Upstream timeout, ms |
230
+ | `use_case` | `x-routeplane-use-case` | Analytics/FinOps label |
231
+ | `log_level` | `x-routeplane-log-level` | `metadata` \| `none` \| `full` |
232
+ | `conversation_id` | `x-routeplane-conversation-id` | Groups a conversation |
233
+ | `currency` | `x-routeplane-currency` | Cost-reporting currency |
234
+ | `metadata` | `x-routeplane-metadata` | Arbitrary tags (JSON) |
235
+ | `pii_mode` | `x-routeplane-pii-mode` | `tokenize` |
236
+ | `output_mask` | `x-routeplane-output-mask` | Output masking policy |
237
+ | `cache_control` | `x-routeplane-cache-control` | `no-store` |
238
+ | `idempotency_key` | `x-routeplane-idempotency-key` | Safe-retry key |
239
+ | `cohort` | `x-routeplane-cohort` | Experiment cohort |
240
+ | `batch` | `x-routeplane-batch` | Batch id |
241
+ | `trace_id` | `x-routeplane-trace-id` | Client trace id (echoed back) |
242
+
243
+ ## Response metadata
244
+
245
+ `RouteplaneMeta.from_headers(response_headers)` (or `client.meta_from_headers(...)`)
246
+ parses the gateway's `x-routeplane-*` response headers: `provider`, `trace_id`,
247
+ `request_id`, `cache`, `guardrails`, `hedged`, `shed`, `budget_remaining`,
248
+ `budget_warning`, `compliance_warning`, `pii_masked`, `idempotent_replayed`.
249
+
250
+ ## Examples
251
+
252
+ Runnable scripts live in [`examples/`](examples):
253
+
254
+ | File | Shows |
255
+ | --- | --- |
256
+ | [`basic.py`](examples/basic.py) | Minimal `Routeplane` client — a drop-in OpenAI subclass |
257
+ | [`headers_only.py`](examples/headers_only.py) | Stock `openai` SDK + `headers()` for per-request steering |
258
+ | [`streaming_with_meta.py`](examples/streaming_with_meta.py) | Streaming with the gateway's decision metadata |
259
+ | [`metadata.py`](examples/metadata.py) | `create_with_meta` — completion plus typed `RouteplaneMeta` |
260
+ | [`resources.py`](examples/resources.py) | Non-OpenAI surfaces — status, logs, FinOps, prompts, cache |
261
+ | [`langchain_integration.py`](examples/langchain_integration.py) | LangChain (`ChatOpenAI`) |
262
+ | [`llamaindex_integration.py`](examples/llamaindex_integration.py) | LlamaIndex (`llama-index-llms-openai`) |
263
+ | [`crewai_integration.py`](examples/crewai_integration.py) | CrewAI (`LLM`) |
264
+
265
+ See [`examples/`](examples) for more.
266
+
267
+ ## Development
268
+
269
+ ```bash
270
+ pip install -e ".[dev]"
271
+ pytest
272
+ ruff check .
273
+ mypy src
274
+ ```
275
+
276
+ ## License
277
+
278
+ Apache-2.0. See [LICENSE](LICENSE).