dvara-ai 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.
- dvara_ai-0.1.0/LICENSE +201 -0
- dvara_ai-0.1.0/PKG-INFO +239 -0
- dvara_ai-0.1.0/README.md +200 -0
- dvara_ai-0.1.0/pyproject.toml +82 -0
- dvara_ai-0.1.0/pyproject.toml.orig +67 -0
- dvara_ai-0.1.0/src/dvara/__init__.py +16 -0
- dvara_ai-0.1.0/src/dvara/cli.py +267 -0
- dvara_ai-0.1.0/src/dvara/pricing.py +181 -0
- dvara_ai-0.1.0/src/dvara/py.typed +0 -0
- dvara_ai-0.1.0/src/dvara/storage.py +352 -0
- dvara_ai-0.1.0/src/dvara/ui/__init__.py +1 -0
- dvara_ai-0.1.0/src/dvara/ui/server.py +59 -0
- dvara_ai-0.1.0/src/dvara/ui/static/chart.umd.min.js +14 -0
- dvara_ai-0.1.0/src/dvara/ui/static/index.html +567 -0
- dvara_ai-0.1.0/src/dvara/wrapper.py +265 -0
dvara_ai-0.1.0/LICENSE
ADDED
|
@@ -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
|
|
95
|
+
Derivative 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 Prasad Thorve
|
|
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.
|
dvara_ai-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dvara-ai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight AI gateway for Python: tracing, cost tracking and a local dashboard for LLM calls.
|
|
5
|
+
Keywords: llm,observability,tracing,cost-tracking,openai,anthropic,claude,ai-gateway,sqlite,dashboard
|
|
6
|
+
Author: Prasad Thorve
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
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: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: System :: Monitoring
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Dist: typer>=0.12
|
|
23
|
+
Requires-Dist: rich>=13
|
|
24
|
+
Requires-Dist: dvara-ai[openai,anthropic,ui] ; extra == 'all'
|
|
25
|
+
Requires-Dist: anthropic>=0.30 ; extra == 'anthropic'
|
|
26
|
+
Requires-Dist: openai>=1.0 ; extra == 'openai'
|
|
27
|
+
Requires-Dist: fastapi>=0.110 ; extra == 'ui'
|
|
28
|
+
Requires-Dist: uvicorn>=0.29 ; extra == 'ui'
|
|
29
|
+
Requires-Python: >=3.10
|
|
30
|
+
Project-URL: Homepage, https://github.com/PrasadThorve/Dvara
|
|
31
|
+
Project-URL: Repository, https://github.com/PrasadThorve/Dvara
|
|
32
|
+
Project-URL: Issues, https://github.com/PrasadThorve/Dvara/issues
|
|
33
|
+
Project-URL: Changelog, https://github.com/PrasadThorve/Dvara/blob/dev/CHANGELOG.md
|
|
34
|
+
Provides-Extra: all
|
|
35
|
+
Provides-Extra: anthropic
|
|
36
|
+
Provides-Extra: openai
|
|
37
|
+
Provides-Extra: ui
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# Dvara
|
|
41
|
+
|
|
42
|
+
**Tracing, cost tracking and a local dashboard for your LLM calls. One line of code, no server, no account.**
|
|
43
|
+
|
|
44
|
+
Wrap your OpenAI or Anthropic client with `dvara.wrap(...)` and every call is recorded to a
|
|
45
|
+
local SQLite file: model, tokens, cost, latency, errors and your own metadata. Inspect it
|
|
46
|
+
from the terminal, from Python (as a list or a pandas DataFrame), or in a dashboard that
|
|
47
|
+
runs on your machine.
|
|
48
|
+
|
|
49
|
+
> **Status:** v0.1, an early release. The API may change before 1.0.
|
|
50
|
+
> Long-term, Dvara aims to be a lightweight AI gateway (one API across providers, fallbacks,
|
|
51
|
+
> caching).
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install "dvara-ai[all]" # or: uv add "dvara-ai[all]"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The package is `dvara-ai`; you import it as `dvara`. The core has only two dependencies
|
|
62
|
+
(`typer`, `rich`); everything else is an optional extra:
|
|
63
|
+
|
|
64
|
+
| Extra | Installs | Needed for |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `openai` | `openai` | wrapping `openai.OpenAI` clients |
|
|
67
|
+
| `anthropic` | `anthropic` | wrapping `anthropic.Anthropic` clients |
|
|
68
|
+
| `ui` | `fastapi`, `uvicorn` | the `dvara ui` dashboard |
|
|
69
|
+
| `all` | all of the above | |
|
|
70
|
+
|
|
71
|
+
Python 3.10 or newer.
|
|
72
|
+
|
|
73
|
+
## Quickstart
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import dvara
|
|
77
|
+
from openai import OpenAI
|
|
78
|
+
from anthropic import Anthropic
|
|
79
|
+
|
|
80
|
+
# Wrap once. Your code and the response objects stay exactly the same.
|
|
81
|
+
openai_client = dvara.wrap(OpenAI(), metadata={"feature": "support-bot"})
|
|
82
|
+
claude = dvara.wrap(Anthropic(), metadata={"feature": "summarizer"})
|
|
83
|
+
|
|
84
|
+
openai_client.chat.completions.create(
|
|
85
|
+
model="gpt-4o-mini",
|
|
86
|
+
messages=[{"role": "user", "content": "Say hi in five words."}],
|
|
87
|
+
)
|
|
88
|
+
claude.messages.create(
|
|
89
|
+
model="claude-haiku-5-5",
|
|
90
|
+
max_tokens=100,
|
|
91
|
+
messages=[{"role": "user", "content": "Say hi in five words."}],
|
|
92
|
+
)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Then look at what happened:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
dvara logs # recent calls
|
|
99
|
+
dvara stats # totals and per-model breakdown
|
|
100
|
+
dvara ui # dashboard at http://127.0.0.1:4000
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Or read traces from Python:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
traces = dvara.get_traces(limit=50, model="gpt-4o-mini", status="success")
|
|
107
|
+
df = dvara.get_traces(as_dataframe=True) # needs pandas installed
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
A runnable version is in [`examples/quickstart.py`](examples/quickstart.py).
|
|
111
|
+
|
|
112
|
+
## Command line
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
$ dvara logs -n 5
|
|
116
|
+
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
|
|
117
|
+
┃ Time ┃ Provider ┃ Model ┃ In ┃ Out ┃ Cost ┃ Latency ┃ Status ┃
|
|
118
|
+
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━┩
|
|
119
|
+
│ 2026-11-29 19:30:05 │ openai │ gpt-6.2-sol │ 3,721 │ 383 │ $0.0113 │ 2.4 s │ success │
|
|
120
|
+
│ 2026-11-29 19:08:39 │ anthropic │ claude-haiku-5… │ 1,649 │ 169 │ $0.000249 │ 521 ms │ success │
|
|
121
|
+
│ 2026-11-29 18:46:33 │ openai │ gpt-5-mini │ 737 │ 482 │ $0.001148 │ 870 ms │ success │
|
|
122
|
+
│ 2026-11-29 18:20:30 │ anthropic │ claude-sonnet-… │ 1,786 │ 815 │ $0.0117 │ 2.1 s │ success │
|
|
123
|
+
│ 2026-11-29 18:02:27 │ anthropic │ claude-opus-5-5 │ 2,321 │ 1,142 │ $0.0321 │ 3.5 s │ success │
|
|
124
|
+
└─────────────────────┴───────────┴─────────────────┴───────┴───────┴───────────┴─────────┴─────────┘
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
| Command | What it does | Options |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| `dvara logs` | Table of the most recent calls | `-n/--limit` (default 20), `--model`, `--status success\|error` |
|
|
130
|
+
| `dvara stats` | Total calls, tokens, cost, average latency and error rate, plus a per-model table | `--model` |
|
|
131
|
+
| `dvara clear` | Delete all traces (asks first) | `-y/--yes` to skip the question |
|
|
132
|
+
| `dvara ui` | Start the local dashboard and open it in your browser | `--port` (default 4000), `--no-browser` |
|
|
133
|
+
|
|
134
|
+
## Dashboard
|
|
135
|
+
|
|
136
|
+
`dvara ui` (needs the `ui` extra) serves a single page with summary cards, cost over time
|
|
137
|
+
(hourly for the last 48 hours or daily for the last 30 days), cost by model, and a
|
|
138
|
+
filterable table of calls. Click a row to see its metadata, error and, if you logged them,
|
|
139
|
+
the prompt and response. New calls appear automatically every 5 seconds. Light and dark
|
|
140
|
+
mode follow your system setting.
|
|
141
|
+
|
|
142
|
+

|
|
143
|
+
|
|
144
|
+
The dashboard only listens on `127.0.0.1` and only answers requests addressed to
|
|
145
|
+
`127.0.0.1` or `localhost`, so it isn't reachable from your network. It is read-only, and
|
|
146
|
+
works offline (Chart.js ships inside the package).
|
|
147
|
+
|
|
148
|
+
## What gets recorded
|
|
149
|
+
|
|
150
|
+
Each call becomes one row in the `traces` table:
|
|
151
|
+
|
|
152
|
+
| Field | Notes |
|
|
153
|
+
|---|---|
|
|
154
|
+
| `id`, `timestamp` | Random hex ID; UTC ISO-8601 time the call started |
|
|
155
|
+
| `provider`, `model` | `openai` or `anthropic`; the model the API reports (e.g. `gpt-4o-mini-2024-07-18`) |
|
|
156
|
+
| `input_tokens`, `output_tokens`, `total_tokens` | Normalized across providers |
|
|
157
|
+
| `cost_usd` | `NULL` if the model's price is unknown |
|
|
158
|
+
| `latency_ms` | Time around the API call only |
|
|
159
|
+
| `status`, `error_type`, `error_message` | `success` or `error`, with the exception's class and message |
|
|
160
|
+
| `metadata` | Whatever you passed to `wrap(..., metadata=...)`, as JSON |
|
|
161
|
+
| `prompt`, `response` | **`NULL` unless you pass `log_content=True`** |
|
|
162
|
+
| `fallback_used` | Always 0 (reserved for v0.3) |
|
|
163
|
+
|
|
164
|
+
**Privacy:** prompt and response text are not stored unless you opt in with
|
|
165
|
+
`dvara.wrap(client, log_content=True)`. Nothing ever leaves your machine; Dvara makes no
|
|
166
|
+
network calls of its own.
|
|
167
|
+
|
|
168
|
+
**Location:** `~/.dvara/traces.db`. Set `DVARA_DB_PATH` to use a different file, for
|
|
169
|
+
example one per project.
|
|
170
|
+
|
|
171
|
+
### Open the database yourself
|
|
172
|
+
|
|
173
|
+
It's a plain SQLite file, so any SQLite tool works:
|
|
174
|
+
|
|
175
|
+
- [DB Browser for SQLite](https://sqlitebrowser.org/): open `~/.dvara/traces.db`.
|
|
176
|
+
- [Datasette](https://datasette.io/): `datasette ~/.dvara/traces.db` for a browsable web UI with SQL.
|
|
177
|
+
- `sqlite3 ~/.dvara/traces.db "SELECT model, SUM(cost_usd) FROM traces GROUP BY model"`
|
|
178
|
+
|
|
179
|
+
## Cost tracking
|
|
180
|
+
|
|
181
|
+
Costs come from a built-in price table (USD per million input and output tokens) taken
|
|
182
|
+
from the official [OpenAI](https://developers.openai.com/api/docs/pricing) and
|
|
183
|
+
[Anthropic](https://platform.claude.com/docs/en/about-claude/pricing) pricing pages. The
|
|
184
|
+
date it was last checked is in `dvara.pricing.PRICES_UPDATED`.
|
|
185
|
+
|
|
186
|
+
- Dated model names find their base model: `gpt-4o-mini-2024-07-18` uses the `gpt-4o-mini`
|
|
187
|
+
price. The longest matching name wins.
|
|
188
|
+
- Models that charge more for long prompts (Claude Haiku 5.5 above 100K input tokens,
|
|
189
|
+
newer GPT models above 272K) use the higher price for those calls.
|
|
190
|
+
- Unknown models get `cost_usd = NULL`, never a guess and never an error. Add or override
|
|
191
|
+
prices yourself:
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
dvara.set_price("my-finetuned-model", input_per_1m=0.30, output_per_1m=1.20)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Not included in v0.1: prompt-cache read/write rates, batch discounts, fast mode and
|
|
198
|
+
data-residency surcharges. If you use prompt caching heavily, actual costs will differ.
|
|
199
|
+
|
|
200
|
+
## Overhead
|
|
201
|
+
|
|
202
|
+
Tracing adds about **27 µs per call**. That's measured on a mocked client that returns
|
|
203
|
+
instantly, so it's only Dvara's own work: reading usage, looking up the price and one SQLite
|
|
204
|
+
write (WAL mode, one reused connection). For comparison, a real LLM call takes hundreds of
|
|
205
|
+
milliseconds or more. Measured on an Apple M5, macOS 26.6, Python 3.12; run
|
|
206
|
+
`uv run pytest tests/test_overhead.py -s` to measure on your machine.
|
|
207
|
+
|
|
208
|
+
## Guarantees
|
|
209
|
+
|
|
210
|
+
- **Tracing never breaks your call.** If writing a trace fails, Dvara logs a warning on the
|
|
211
|
+
`dvara` logger and you still get the real response.
|
|
212
|
+
- **Errors are untouched.** If the API call raises, Dvara records an error trace and
|
|
213
|
+
re-raises the original exception unchanged.
|
|
214
|
+
- **Same objects.** You get back the SDK's own response objects, not copies or wrappers.
|
|
215
|
+
|
|
216
|
+
## Limitations in v0.1
|
|
217
|
+
|
|
218
|
+
- Streaming calls (`stream=True`) pass through but aren't traced.
|
|
219
|
+
- Async clients (`AsyncOpenAI`, `AsyncAnthropic`) aren't supported yet.
|
|
220
|
+
- Clients created with `client.with_options(...)`, and `.with_raw_response` calls, aren't traced.
|
|
221
|
+
- Only `chat.completions.create` (OpenAI) and `messages.create` (Anthropic) are traced.
|
|
222
|
+
- Anthropic prompt-cache tokens aren't counted in `input_tokens` or cost.
|
|
223
|
+
|
|
224
|
+
These are planned for future releases.
|
|
225
|
+
|
|
226
|
+
## Development
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
uv sync --all-extras # install everything
|
|
230
|
+
uv run pytest # tests use mocked clients: no keys, no network
|
|
231
|
+
uv run python scripts/seed_demo_data.py # fake traces for working on the dashboard
|
|
232
|
+
uv run dvara ui
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
The seed script writes to `~/.dvara/traces.db` unless you set `DVARA_DB_PATH`.
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
[Apache-2.0](LICENSE)
|
dvara_ai-0.1.0/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Dvara
|
|
2
|
+
|
|
3
|
+
**Tracing, cost tracking and a local dashboard for your LLM calls. One line of code, no server, no account.**
|
|
4
|
+
|
|
5
|
+
Wrap your OpenAI or Anthropic client with `dvara.wrap(...)` and every call is recorded to a
|
|
6
|
+
local SQLite file: model, tokens, cost, latency, errors and your own metadata. Inspect it
|
|
7
|
+
from the terminal, from Python (as a list or a pandas DataFrame), or in a dashboard that
|
|
8
|
+
runs on your machine.
|
|
9
|
+
|
|
10
|
+
> **Status:** v0.1, an early release. The API may change before 1.0.
|
|
11
|
+
> Long-term, Dvara aims to be a lightweight AI gateway (one API across providers, fallbacks,
|
|
12
|
+
> caching).
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install "dvara-ai[all]" # or: uv add "dvara-ai[all]"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The package is `dvara-ai`; you import it as `dvara`. The core has only two dependencies
|
|
23
|
+
(`typer`, `rich`); everything else is an optional extra:
|
|
24
|
+
|
|
25
|
+
| Extra | Installs | Needed for |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| `openai` | `openai` | wrapping `openai.OpenAI` clients |
|
|
28
|
+
| `anthropic` | `anthropic` | wrapping `anthropic.Anthropic` clients |
|
|
29
|
+
| `ui` | `fastapi`, `uvicorn` | the `dvara ui` dashboard |
|
|
30
|
+
| `all` | all of the above | |
|
|
31
|
+
|
|
32
|
+
Python 3.10 or newer.
|
|
33
|
+
|
|
34
|
+
## Quickstart
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import dvara
|
|
38
|
+
from openai import OpenAI
|
|
39
|
+
from anthropic import Anthropic
|
|
40
|
+
|
|
41
|
+
# Wrap once. Your code and the response objects stay exactly the same.
|
|
42
|
+
openai_client = dvara.wrap(OpenAI(), metadata={"feature": "support-bot"})
|
|
43
|
+
claude = dvara.wrap(Anthropic(), metadata={"feature": "summarizer"})
|
|
44
|
+
|
|
45
|
+
openai_client.chat.completions.create(
|
|
46
|
+
model="gpt-4o-mini",
|
|
47
|
+
messages=[{"role": "user", "content": "Say hi in five words."}],
|
|
48
|
+
)
|
|
49
|
+
claude.messages.create(
|
|
50
|
+
model="claude-haiku-5-5",
|
|
51
|
+
max_tokens=100,
|
|
52
|
+
messages=[{"role": "user", "content": "Say hi in five words."}],
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Then look at what happened:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
dvara logs # recent calls
|
|
60
|
+
dvara stats # totals and per-model breakdown
|
|
61
|
+
dvara ui # dashboard at http://127.0.0.1:4000
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Or read traces from Python:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
traces = dvara.get_traces(limit=50, model="gpt-4o-mini", status="success")
|
|
68
|
+
df = dvara.get_traces(as_dataframe=True) # needs pandas installed
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
A runnable version is in [`examples/quickstart.py`](examples/quickstart.py).
|
|
72
|
+
|
|
73
|
+
## Command line
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
$ dvara logs -n 5
|
|
77
|
+
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
|
|
78
|
+
┃ Time ┃ Provider ┃ Model ┃ In ┃ Out ┃ Cost ┃ Latency ┃ Status ┃
|
|
79
|
+
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━┩
|
|
80
|
+
│ 2026-11-29 19:30:05 │ openai │ gpt-6.2-sol │ 3,721 │ 383 │ $0.0113 │ 2.4 s │ success │
|
|
81
|
+
│ 2026-11-29 19:08:39 │ anthropic │ claude-haiku-5… │ 1,649 │ 169 │ $0.000249 │ 521 ms │ success │
|
|
82
|
+
│ 2026-11-29 18:46:33 │ openai │ gpt-5-mini │ 737 │ 482 │ $0.001148 │ 870 ms │ success │
|
|
83
|
+
│ 2026-11-29 18:20:30 │ anthropic │ claude-sonnet-… │ 1,786 │ 815 │ $0.0117 │ 2.1 s │ success │
|
|
84
|
+
│ 2026-11-29 18:02:27 │ anthropic │ claude-opus-5-5 │ 2,321 │ 1,142 │ $0.0321 │ 3.5 s │ success │
|
|
85
|
+
└─────────────────────┴───────────┴─────────────────┴───────┴───────┴───────────┴─────────┴─────────┘
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
| Command | What it does | Options |
|
|
89
|
+
|---|---|---|
|
|
90
|
+
| `dvara logs` | Table of the most recent calls | `-n/--limit` (default 20), `--model`, `--status success\|error` |
|
|
91
|
+
| `dvara stats` | Total calls, tokens, cost, average latency and error rate, plus a per-model table | `--model` |
|
|
92
|
+
| `dvara clear` | Delete all traces (asks first) | `-y/--yes` to skip the question |
|
|
93
|
+
| `dvara ui` | Start the local dashboard and open it in your browser | `--port` (default 4000), `--no-browser` |
|
|
94
|
+
|
|
95
|
+
## Dashboard
|
|
96
|
+
|
|
97
|
+
`dvara ui` (needs the `ui` extra) serves a single page with summary cards, cost over time
|
|
98
|
+
(hourly for the last 48 hours or daily for the last 30 days), cost by model, and a
|
|
99
|
+
filterable table of calls. Click a row to see its metadata, error and, if you logged them,
|
|
100
|
+
the prompt and response. New calls appear automatically every 5 seconds. Light and dark
|
|
101
|
+
mode follow your system setting.
|
|
102
|
+
|
|
103
|
+

|
|
104
|
+
|
|
105
|
+
The dashboard only listens on `127.0.0.1` and only answers requests addressed to
|
|
106
|
+
`127.0.0.1` or `localhost`, so it isn't reachable from your network. It is read-only, and
|
|
107
|
+
works offline (Chart.js ships inside the package).
|
|
108
|
+
|
|
109
|
+
## What gets recorded
|
|
110
|
+
|
|
111
|
+
Each call becomes one row in the `traces` table:
|
|
112
|
+
|
|
113
|
+
| Field | Notes |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `id`, `timestamp` | Random hex ID; UTC ISO-8601 time the call started |
|
|
116
|
+
| `provider`, `model` | `openai` or `anthropic`; the model the API reports (e.g. `gpt-4o-mini-2024-07-18`) |
|
|
117
|
+
| `input_tokens`, `output_tokens`, `total_tokens` | Normalized across providers |
|
|
118
|
+
| `cost_usd` | `NULL` if the model's price is unknown |
|
|
119
|
+
| `latency_ms` | Time around the API call only |
|
|
120
|
+
| `status`, `error_type`, `error_message` | `success` or `error`, with the exception's class and message |
|
|
121
|
+
| `metadata` | Whatever you passed to `wrap(..., metadata=...)`, as JSON |
|
|
122
|
+
| `prompt`, `response` | **`NULL` unless you pass `log_content=True`** |
|
|
123
|
+
| `fallback_used` | Always 0 (reserved for v0.3) |
|
|
124
|
+
|
|
125
|
+
**Privacy:** prompt and response text are not stored unless you opt in with
|
|
126
|
+
`dvara.wrap(client, log_content=True)`. Nothing ever leaves your machine; Dvara makes no
|
|
127
|
+
network calls of its own.
|
|
128
|
+
|
|
129
|
+
**Location:** `~/.dvara/traces.db`. Set `DVARA_DB_PATH` to use a different file, for
|
|
130
|
+
example one per project.
|
|
131
|
+
|
|
132
|
+
### Open the database yourself
|
|
133
|
+
|
|
134
|
+
It's a plain SQLite file, so any SQLite tool works:
|
|
135
|
+
|
|
136
|
+
- [DB Browser for SQLite](https://sqlitebrowser.org/): open `~/.dvara/traces.db`.
|
|
137
|
+
- [Datasette](https://datasette.io/): `datasette ~/.dvara/traces.db` for a browsable web UI with SQL.
|
|
138
|
+
- `sqlite3 ~/.dvara/traces.db "SELECT model, SUM(cost_usd) FROM traces GROUP BY model"`
|
|
139
|
+
|
|
140
|
+
## Cost tracking
|
|
141
|
+
|
|
142
|
+
Costs come from a built-in price table (USD per million input and output tokens) taken
|
|
143
|
+
from the official [OpenAI](https://developers.openai.com/api/docs/pricing) and
|
|
144
|
+
[Anthropic](https://platform.claude.com/docs/en/about-claude/pricing) pricing pages. The
|
|
145
|
+
date it was last checked is in `dvara.pricing.PRICES_UPDATED`.
|
|
146
|
+
|
|
147
|
+
- Dated model names find their base model: `gpt-4o-mini-2024-07-18` uses the `gpt-4o-mini`
|
|
148
|
+
price. The longest matching name wins.
|
|
149
|
+
- Models that charge more for long prompts (Claude Haiku 5.5 above 100K input tokens,
|
|
150
|
+
newer GPT models above 272K) use the higher price for those calls.
|
|
151
|
+
- Unknown models get `cost_usd = NULL`, never a guess and never an error. Add or override
|
|
152
|
+
prices yourself:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
dvara.set_price("my-finetuned-model", input_per_1m=0.30, output_per_1m=1.20)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Not included in v0.1: prompt-cache read/write rates, batch discounts, fast mode and
|
|
159
|
+
data-residency surcharges. If you use prompt caching heavily, actual costs will differ.
|
|
160
|
+
|
|
161
|
+
## Overhead
|
|
162
|
+
|
|
163
|
+
Tracing adds about **27 µs per call**. That's measured on a mocked client that returns
|
|
164
|
+
instantly, so it's only Dvara's own work: reading usage, looking up the price and one SQLite
|
|
165
|
+
write (WAL mode, one reused connection). For comparison, a real LLM call takes hundreds of
|
|
166
|
+
milliseconds or more. Measured on an Apple M5, macOS 26.6, Python 3.12; run
|
|
167
|
+
`uv run pytest tests/test_overhead.py -s` to measure on your machine.
|
|
168
|
+
|
|
169
|
+
## Guarantees
|
|
170
|
+
|
|
171
|
+
- **Tracing never breaks your call.** If writing a trace fails, Dvara logs a warning on the
|
|
172
|
+
`dvara` logger and you still get the real response.
|
|
173
|
+
- **Errors are untouched.** If the API call raises, Dvara records an error trace and
|
|
174
|
+
re-raises the original exception unchanged.
|
|
175
|
+
- **Same objects.** You get back the SDK's own response objects, not copies or wrappers.
|
|
176
|
+
|
|
177
|
+
## Limitations in v0.1
|
|
178
|
+
|
|
179
|
+
- Streaming calls (`stream=True`) pass through but aren't traced.
|
|
180
|
+
- Async clients (`AsyncOpenAI`, `AsyncAnthropic`) aren't supported yet.
|
|
181
|
+
- Clients created with `client.with_options(...)`, and `.with_raw_response` calls, aren't traced.
|
|
182
|
+
- Only `chat.completions.create` (OpenAI) and `messages.create` (Anthropic) are traced.
|
|
183
|
+
- Anthropic prompt-cache tokens aren't counted in `input_tokens` or cost.
|
|
184
|
+
|
|
185
|
+
These are planned for future releases.
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
uv sync --all-extras # install everything
|
|
191
|
+
uv run pytest # tests use mocked clients: no keys, no network
|
|
192
|
+
uv run python scripts/seed_demo_data.py # fake traces for working on the dashboard
|
|
193
|
+
uv run dvara ui
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
The seed script writes to `~/.dvara/traces.db` unless you set `DVARA_DB_PATH`.
|
|
197
|
+
|
|
198
|
+
## License
|
|
199
|
+
|
|
200
|
+
[Apache-2.0](LICENSE)
|