Spryngtime Usage Analytics & Billing API
Table of Contents
Requirements
Python >=3.7
Installing
pip install spryngtime-analytics-sdk-python-sdk==1.0.1
Getting Started
from pprint import pprint
from spryngtime_analytics_sdk import SpryngtimeAnalyticsSdk, ApiException
spryngtimeanalyticssdk = SpryngtimeAnalyticsSdk(
api_key="YOUR_API_KEY",
)
try:
# Track usage data
spryngtimeanalyticssdk.usage_tracking.track_usage(
key="string_example",
open_ai_response={
"id": "id_example",
"object": "object_example",
"created": 1,
"model": "model_example",
"choices": [
{
"index": 1,
"message": {
"role": "role_example",
"content": "content_example",
},
"finish_reason": "finish_reason_example",
}
],
"usage": {
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1,
},
},
usage={
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1,
},
)
except ApiException as e:
print("Exception when calling UsageTrackingApi.track_usage: %s\n" % e)
pprint(e.body)
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
Async
async
support is available by prepending a
to any method.
import asyncio
from pprint import pprint
from spryngtime_analytics_sdk import SpryngtimeAnalyticsSdk, ApiException
spryngtimeanalyticssdk = SpryngtimeAnalyticsSdk(
api_key="YOUR_API_KEY",
)
async def main():
try:
# Track usage data
await spryngtimeanalyticssdk.usage_tracking.atrack_usage(
key="string_example",
open_ai_response={
"id": "id_example",
"object": "object_example",
"created": 1,
"model": "model_example",
"choices": [
{
"index": 1,
"message": {
"role": "role_example",
"content": "content_example",
},
"finish_reason": "finish_reason_example",
}
],
"usage": {
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1,
},
},
usage={
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1,
},
)
except ApiException as e:
print("Exception when calling UsageTrackingApi.track_usage: %s\n" % e)
pprint(e.body)
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
asyncio.run(main())
Raw HTTP Response
To access raw HTTP response values, use the .raw
namespace.
from pprint import pprint
from spryngtime_analytics_sdk import SpryngtimeAnalyticsSdk, ApiException
spryngtimeanalyticssdk = SpryngtimeAnalyticsSdk(
api_key="YOUR_API_KEY",
)
try:
# Track usage data
track_usage_response = spryngtimeanalyticssdk.usage_tracking.raw.track_usage(
key="string_example",
open_ai_response={
"id": "id_example",
"object": "object_example",
"created": 1,
"model": "model_example",
"choices": [
{
"index": 1,
"message": {
"role": "role_example",
"content": "content_example",
},
"finish_reason": "finish_reason_example",
}
],
"usage": {
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1,
},
},
usage={
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1,
},
)
pprint(track_usage_response.headers)
pprint(track_usage_response.status)
pprint(track_usage_response.round_trip_time)
except ApiException as e:
print("Exception when calling UsageTrackingApi.track_usage: %s\n" % e)
pprint(e.body)
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
Reference
spryngtimeanalyticssdk.usage_tracking.track_usage
Track usage data
🛠️ Usage
spryngtimeanalyticssdk.usage_tracking.track_usage(
key="string_example",
open_ai_response={
"id": "id_example",
"object": "object_example",
"created": 1,
"model": "model_example",
"choices": [
{
"index": 1,
"message": {
"role": "role_example",
"content": "content_example",
},
"finish_reason": "finish_reason_example",
}
],
"usage": {
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1,
},
},
usage={
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1,
},
)
⚙️ Parameters
key: str
open_ai_response: OpenAiResponse
usage: UsageDetail
⚙️ Request Body
🌐 Endpoint
/trackUsage
post
spryngtimeanalyticssdk.default.root_get
Home
🛠️ Usage
spryngtimeanalyticssdk.default.root_get()
🌐 Endpoint
/
get
spryngtimeanalyticssdk.default.users_post
Adds a new user
🛠️ Usage
spryngtimeanalyticssdk.default.users_post(
id=10,
name="Jessica Smith",
)
⚙️ Parameters
id: int
name: str
⚙️ Request Body
🌐 Endpoint
/users
post
Author
This Python package is automatically generated by Konfig