withorbit-sdk 0.1.3__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,233 @@
1
+ Metadata-Version: 2.4
2
+ Name: withorbit-sdk
3
+ Version: 0.1.3
4
+ Summary: Orbit - AI Cost Analytics SDK. Track, monitor, and optimize your AI spend.
5
+ Author-email: WithOrbit <support@withorbit.io>
6
+ License: MIT
7
+ Project-URL: Homepage, https://withorbit.io
8
+ Project-URL: Documentation, https://withorbit.io/docs
9
+ Project-URL: Repository, https://github.com/withorbit/sdk-python
10
+ Keywords: ai,llm,analytics,monitoring,openai,anthropic,cost-tracking,observability,orbit,withorbit
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+ Requires-Dist: httpx>=0.24.0
24
+ Provides-Extra: openai
25
+ Requires-Dist: openai>=1.0.0; extra == "openai"
26
+ Provides-Extra: anthropic
27
+ Requires-Dist: anthropic>=0.18.0; extra == "anthropic"
28
+ Provides-Extra: google
29
+ Requires-Dist: google-genai>=1.0.0; extra == "google"
30
+ Provides-Extra: all
31
+ Requires-Dist: openai>=1.0.0; extra == "all"
32
+ Requires-Dist: anthropic>=0.18.0; extra == "all"
33
+ Requires-Dist: google-genai>=1.0.0; extra == "all"
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
36
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
37
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
38
+
39
+ # Orbit SDK for Python
40
+
41
+ Track, monitor, and optimize your AI spend across OpenAI, Anthropic, and other LLM providers.
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ pip install withorbit-sdk
47
+
48
+ # With OpenAI support
49
+ pip install withorbit-sdk[openai]
50
+
51
+ # With Anthropic support
52
+ pip install withorbit-sdk[anthropic]
53
+
54
+ # With all providers
55
+ pip install withorbit-sdk[all]
56
+ ```
57
+
58
+ ## Quick Start
59
+
60
+ ### 1. Get your API key
61
+
62
+ Sign up at [Orbit](https://app.withorbit.io) and create an API key.
63
+
64
+ ### 2. Initialize the SDK
65
+
66
+ ```python
67
+ from withorbit_sdk import Orbit
68
+
69
+ orbit = Orbit(
70
+ api_key="orb_live_xxxxxxxxxxxxxxxxxxxxxxxx",
71
+ default_feature="my-app", # Optional: default feature for all events
72
+ )
73
+ ```
74
+
75
+ ### 3. Track your LLM calls
76
+
77
+ #### Option A: Automatic tracking (Recommended)
78
+
79
+ Wrap your OpenAI or Anthropic client for automatic tracking:
80
+
81
+ ```python
82
+ from openai import OpenAI
83
+ from withorbit_sdk import Orbit, WrapperOptions
84
+
85
+ orbit = Orbit(api_key="orb_live_xxx")
86
+ openai = orbit.wrap_openai(OpenAI(), WrapperOptions(feature="chat-assistant"))
87
+
88
+ # All API calls are now automatically tracked!
89
+ response = openai.chat.completions.create(
90
+ model="gpt-4o",
91
+ messages=[{"role": "user", "content": "Hello, world!"}],
92
+ )
93
+ ```
94
+
95
+ Works with Anthropic too:
96
+
97
+ ```python
98
+ from anthropic import Anthropic
99
+ from withorbit_sdk import Orbit, WrapperOptions
100
+
101
+ orbit = Orbit(api_key="orb_live_xxx")
102
+ anthropic = orbit.wrap_anthropic(Anthropic(), WrapperOptions(feature="document-analysis"))
103
+
104
+ message = anthropic.messages.create(
105
+ model="claude-3-opus-20240229",
106
+ max_tokens=1024,
107
+ messages=[{"role": "user", "content": "Analyze this document..."}],
108
+ )
109
+ ```
110
+
111
+ #### Option B: Manual tracking
112
+
113
+ For other providers or custom implementations:
114
+
115
+ ```python
116
+ from withorbit_sdk import Orbit
117
+
118
+ orbit = Orbit(api_key="orb_live_xxx")
119
+
120
+ # Track a successful request
121
+ orbit.track(
122
+ model="gpt-4o",
123
+ input_tokens=150,
124
+ output_tokens=50,
125
+ latency_ms=1234,
126
+ feature="summarization",
127
+ environment="production",
128
+ )
129
+
130
+ # Track an error
131
+ orbit.track_error(
132
+ model="gpt-4o",
133
+ error_type="rate_limit_exceeded",
134
+ error_message="Rate limit exceeded",
135
+ feature="chat-assistant",
136
+ input_tokens=150,
137
+ )
138
+ ```
139
+
140
+ ## Configuration
141
+
142
+ ```python
143
+ from withorbit_sdk import Orbit, OrbitConfig
144
+
145
+ orbit = Orbit(config=OrbitConfig(
146
+ # Required
147
+ api_key="orb_live_xxx",
148
+
149
+ # Optional
150
+ base_url="https://app.withorbit.io/api/v1", # Custom API endpoint
151
+ default_feature="my-app", # Default feature name
152
+ default_environment="production", # 'production' | 'staging' | 'development'
153
+ debug=False, # Enable debug logging
154
+
155
+ # Batching (for high-volume applications)
156
+ batch_events=True, # Batch events before sending
157
+ batch_size=10, # Max events per batch
158
+ batch_interval=5.0, # Max seconds before sending batch
159
+
160
+ # Reliability
161
+ retry=True, # Retry failed requests
162
+ max_retries=3, # Max retry attempts
163
+ ))
164
+ ```
165
+
166
+ ## Feature Attribution
167
+
168
+ Features are Orbit's key differentiator - they let you see exactly which parts of your application are consuming AI resources:
169
+
170
+ ```python
171
+ # Track different features
172
+ orbit.track(
173
+ model="gpt-4o",
174
+ input_tokens=100,
175
+ output_tokens=50,
176
+ feature="chat-assistant", # Attribute to chat feature
177
+ )
178
+
179
+ orbit.track(
180
+ model="gpt-4o",
181
+ input_tokens=500,
182
+ output_tokens=200,
183
+ feature="document-analysis", # Attribute to doc analysis
184
+ )
185
+ ```
186
+
187
+ Then in the Orbit dashboard, you'll see:
188
+ - Cost breakdown by feature
189
+ - Request volume by feature
190
+ - Error rates by feature
191
+ - And more!
192
+
193
+ ## Context Manager Support
194
+
195
+ ```python
196
+ from withorbit_sdk import Orbit
197
+
198
+ with Orbit(api_key="orb_live_xxx") as orbit:
199
+ orbit.track(model="gpt-4o", input_tokens=100, output_tokens=50)
200
+ # Automatically flushes on exit
201
+ ```
202
+
203
+ ## Graceful Shutdown
204
+
205
+ For long-running processes, flush events before exit:
206
+
207
+ ```python
208
+ # Before your process exits
209
+ orbit.shutdown()
210
+ ```
211
+
212
+ ## Event Properties
213
+
214
+ | Property | Type | Required | Description |
215
+ |----------|------|----------|-------------|
216
+ | `model` | str | Yes | Model name (e.g., 'gpt-4o', 'claude-3-opus') |
217
+ | `input_tokens` | int | Yes | Number of input tokens |
218
+ | `output_tokens` | int | Yes | Number of output tokens |
219
+ | `provider` | str | No | Provider name (auto-detected if not provided) |
220
+ | `latency_ms` | int | No | Request latency in milliseconds |
221
+ | `feature` | str | No | Feature name for attribution |
222
+ | `environment` | str | No | Environment ('production', 'staging', 'development') |
223
+ | `status` | str | No | Request status ('success', 'error', 'timeout') |
224
+ | `error_type` | str | No | Error type if status is 'error' |
225
+ | `error_message` | str | No | Error message if status is 'error' |
226
+ | `user_id` | str | No | Your application's user ID |
227
+ | `session_id` | str | No | Session ID for grouping requests |
228
+ | `request_id` | str | No | Unique request ID for tracing |
229
+ | `metadata` | dict | No | Additional key-value metadata |
230
+
231
+ ## License
232
+
233
+ MIT
@@ -0,0 +1,195 @@
1
+ # Orbit SDK for Python
2
+
3
+ Track, monitor, and optimize your AI spend across OpenAI, Anthropic, and other LLM providers.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install withorbit-sdk
9
+
10
+ # With OpenAI support
11
+ pip install withorbit-sdk[openai]
12
+
13
+ # With Anthropic support
14
+ pip install withorbit-sdk[anthropic]
15
+
16
+ # With all providers
17
+ pip install withorbit-sdk[all]
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ### 1. Get your API key
23
+
24
+ Sign up at [Orbit](https://app.withorbit.io) and create an API key.
25
+
26
+ ### 2. Initialize the SDK
27
+
28
+ ```python
29
+ from withorbit_sdk import Orbit
30
+
31
+ orbit = Orbit(
32
+ api_key="orb_live_xxxxxxxxxxxxxxxxxxxxxxxx",
33
+ default_feature="my-app", # Optional: default feature for all events
34
+ )
35
+ ```
36
+
37
+ ### 3. Track your LLM calls
38
+
39
+ #### Option A: Automatic tracking (Recommended)
40
+
41
+ Wrap your OpenAI or Anthropic client for automatic tracking:
42
+
43
+ ```python
44
+ from openai import OpenAI
45
+ from withorbit_sdk import Orbit, WrapperOptions
46
+
47
+ orbit = Orbit(api_key="orb_live_xxx")
48
+ openai = orbit.wrap_openai(OpenAI(), WrapperOptions(feature="chat-assistant"))
49
+
50
+ # All API calls are now automatically tracked!
51
+ response = openai.chat.completions.create(
52
+ model="gpt-4o",
53
+ messages=[{"role": "user", "content": "Hello, world!"}],
54
+ )
55
+ ```
56
+
57
+ Works with Anthropic too:
58
+
59
+ ```python
60
+ from anthropic import Anthropic
61
+ from withorbit_sdk import Orbit, WrapperOptions
62
+
63
+ orbit = Orbit(api_key="orb_live_xxx")
64
+ anthropic = orbit.wrap_anthropic(Anthropic(), WrapperOptions(feature="document-analysis"))
65
+
66
+ message = anthropic.messages.create(
67
+ model="claude-3-opus-20240229",
68
+ max_tokens=1024,
69
+ messages=[{"role": "user", "content": "Analyze this document..."}],
70
+ )
71
+ ```
72
+
73
+ #### Option B: Manual tracking
74
+
75
+ For other providers or custom implementations:
76
+
77
+ ```python
78
+ from withorbit_sdk import Orbit
79
+
80
+ orbit = Orbit(api_key="orb_live_xxx")
81
+
82
+ # Track a successful request
83
+ orbit.track(
84
+ model="gpt-4o",
85
+ input_tokens=150,
86
+ output_tokens=50,
87
+ latency_ms=1234,
88
+ feature="summarization",
89
+ environment="production",
90
+ )
91
+
92
+ # Track an error
93
+ orbit.track_error(
94
+ model="gpt-4o",
95
+ error_type="rate_limit_exceeded",
96
+ error_message="Rate limit exceeded",
97
+ feature="chat-assistant",
98
+ input_tokens=150,
99
+ )
100
+ ```
101
+
102
+ ## Configuration
103
+
104
+ ```python
105
+ from withorbit_sdk import Orbit, OrbitConfig
106
+
107
+ orbit = Orbit(config=OrbitConfig(
108
+ # Required
109
+ api_key="orb_live_xxx",
110
+
111
+ # Optional
112
+ base_url="https://app.withorbit.io/api/v1", # Custom API endpoint
113
+ default_feature="my-app", # Default feature name
114
+ default_environment="production", # 'production' | 'staging' | 'development'
115
+ debug=False, # Enable debug logging
116
+
117
+ # Batching (for high-volume applications)
118
+ batch_events=True, # Batch events before sending
119
+ batch_size=10, # Max events per batch
120
+ batch_interval=5.0, # Max seconds before sending batch
121
+
122
+ # Reliability
123
+ retry=True, # Retry failed requests
124
+ max_retries=3, # Max retry attempts
125
+ ))
126
+ ```
127
+
128
+ ## Feature Attribution
129
+
130
+ Features are Orbit's key differentiator - they let you see exactly which parts of your application are consuming AI resources:
131
+
132
+ ```python
133
+ # Track different features
134
+ orbit.track(
135
+ model="gpt-4o",
136
+ input_tokens=100,
137
+ output_tokens=50,
138
+ feature="chat-assistant", # Attribute to chat feature
139
+ )
140
+
141
+ orbit.track(
142
+ model="gpt-4o",
143
+ input_tokens=500,
144
+ output_tokens=200,
145
+ feature="document-analysis", # Attribute to doc analysis
146
+ )
147
+ ```
148
+
149
+ Then in the Orbit dashboard, you'll see:
150
+ - Cost breakdown by feature
151
+ - Request volume by feature
152
+ - Error rates by feature
153
+ - And more!
154
+
155
+ ## Context Manager Support
156
+
157
+ ```python
158
+ from withorbit_sdk import Orbit
159
+
160
+ with Orbit(api_key="orb_live_xxx") as orbit:
161
+ orbit.track(model="gpt-4o", input_tokens=100, output_tokens=50)
162
+ # Automatically flushes on exit
163
+ ```
164
+
165
+ ## Graceful Shutdown
166
+
167
+ For long-running processes, flush events before exit:
168
+
169
+ ```python
170
+ # Before your process exits
171
+ orbit.shutdown()
172
+ ```
173
+
174
+ ## Event Properties
175
+
176
+ | Property | Type | Required | Description |
177
+ |----------|------|----------|-------------|
178
+ | `model` | str | Yes | Model name (e.g., 'gpt-4o', 'claude-3-opus') |
179
+ | `input_tokens` | int | Yes | Number of input tokens |
180
+ | `output_tokens` | int | Yes | Number of output tokens |
181
+ | `provider` | str | No | Provider name (auto-detected if not provided) |
182
+ | `latency_ms` | int | No | Request latency in milliseconds |
183
+ | `feature` | str | No | Feature name for attribution |
184
+ | `environment` | str | No | Environment ('production', 'staging', 'development') |
185
+ | `status` | str | No | Request status ('success', 'error', 'timeout') |
186
+ | `error_type` | str | No | Error type if status is 'error' |
187
+ | `error_message` | str | No | Error message if status is 'error' |
188
+ | `user_id` | str | No | Your application's user ID |
189
+ | `session_id` | str | No | Session ID for grouping requests |
190
+ | `request_id` | str | No | Unique request ID for tracing |
191
+ | `metadata` | dict | No | Additional key-value metadata |
192
+
193
+ ## License
194
+
195
+ MIT
@@ -0,0 +1,49 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "withorbit-sdk"
7
+ version = "0.1.3"
8
+ description = "Orbit - AI Cost Analytics SDK. Track, monitor, and optimize your AI spend."
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ authors = [
12
+ {name = "WithOrbit", email = "support@withorbit.io"}
13
+ ]
14
+ keywords = ["ai", "llm", "analytics", "monitoring", "openai", "anthropic", "cost-tracking", "observability", "orbit", "withorbit"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.8",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Software Development :: Libraries :: Python Modules",
26
+ ]
27
+ requires-python = ">=3.8"
28
+ dependencies = [
29
+ "httpx>=0.24.0",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ openai = ["openai>=1.0.0"]
34
+ anthropic = ["anthropic>=0.18.0"]
35
+ google = ["google-genai>=1.0.0"]
36
+ all = ["openai>=1.0.0", "anthropic>=0.18.0", "google-genai>=1.0.0"]
37
+ dev = ["pytest>=7.0.0", "pytest-asyncio>=0.21.0", "mypy>=1.0.0"]
38
+
39
+ [project.urls]
40
+ Homepage = "https://withorbit.io"
41
+ Documentation = "https://withorbit.io/docs"
42
+ Repository = "https://github.com/withorbit/sdk-python"
43
+
44
+ [tool.setuptools.packages.find]
45
+ where = ["."]
46
+
47
+ [tool.mypy]
48
+ python_version = "3.8"
49
+ strict = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,40 @@
1
+ """
2
+ Orbit SDK
3
+ Track, monitor, and optimize your AI spend
4
+
5
+ Usage:
6
+ from withorbit_sdk import Orbit
7
+
8
+ orbit = Orbit(api_key="orb_live_xxx")
9
+
10
+ # Manual tracking
11
+ orbit.track(
12
+ model="gpt-4o",
13
+ input_tokens=100,
14
+ output_tokens=50,
15
+ feature="chat-assistant",
16
+ )
17
+
18
+ # Or wrap your OpenAI/Anthropic client for automatic tracking
19
+ from openai import OpenAI
20
+
21
+ openai = orbit.wrap_openai(OpenAI())
22
+ response = openai.chat.completions.create(
23
+ model="gpt-4o",
24
+ messages=[{"role": "user", "content": "Hello!"}],
25
+ )
26
+ # Usage automatically tracked!
27
+ """
28
+
29
+ from .client import OrbitClient, Orbit
30
+ from .types import OrbitConfig, OrbitEvent, OrbitResponse, WrapperOptions
31
+
32
+ __version__ = "0.1.3"
33
+ __all__ = [
34
+ "Orbit",
35
+ "OrbitClient",
36
+ "OrbitConfig",
37
+ "OrbitEvent",
38
+ "OrbitResponse",
39
+ "WrapperOptions",
40
+ ]