Skip to content

Commit b4bfef2

Browse files
committed
added new model and new erro contract
1 parent 4f3a6ae commit b4bfef2

17 files changed

Lines changed: 1650 additions & 358 deletions

‎examples/flowstate_simple_example.ipynb‎

Lines changed: 81 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616
"cell_type": "code",
1717
"metadata": {
1818
"ExecuteTime": {
19-
"end_time": "2025-10-30T16:19:55.580574Z",
20-
"start_time": "2025-10-30T16:19:55.572729Z"
19+
"end_time": "2025-11-02T13:09:29.782458Z",
20+
"start_time": "2025-11-02T13:09:29.780008Z"
2121
}
2222
},
2323
"source": [
2424
"# Install dependencies if needed\n",
2525
"# !pip install numpy pandas matplotlib statsmodels"
2626
],
2727
"outputs": [],
28-
"execution_count": 60
28+
"execution_count": 1
2929
},
3030
{
3131
"cell_type": "code",
3232
"metadata": {
3333
"ExecuteTime": {
34-
"end_time": "2025-10-30T16:19:55.594776Z",
35-
"start_time": "2025-10-30T16:19:55.592104Z"
34+
"end_time": "2025-11-02T13:09:30.664688Z",
35+
"start_time": "2025-11-02T13:09:29.885721Z"
3636
}
3737
},
3838
"source": [
@@ -48,7 +48,7 @@
4848
"from faim_sdk import FlowStateForecastRequest, ForecastClient"
4949
],
5050
"outputs": [],
51-
"execution_count": 61
51+
"execution_count": 2
5252
},
5353
{
5454
"cell_type": "markdown",
@@ -59,8 +59,8 @@
5959
"cell_type": "code",
6060
"metadata": {
6161
"ExecuteTime": {
62-
"end_time": "2025-10-30T16:19:55.637833Z",
63-
"start_time": "2025-10-30T16:19:55.620782Z"
62+
"end_time": "2025-11-02T13:09:31.749271Z",
63+
"start_time": "2025-11-02T13:09:30.681133Z"
6464
}
6565
},
6666
"source": [
@@ -106,14 +106,14 @@
106106
]
107107
}
108108
],
109-
"execution_count": 62
109+
"execution_count": 3
110110
},
111111
{
112112
"cell_type": "code",
113113
"metadata": {
114114
"ExecuteTime": {
115-
"end_time": "2025-10-30T16:19:55.666166Z",
116-
"start_time": "2025-10-30T16:19:55.660954Z"
115+
"end_time": "2025-11-02T13:09:31.764649Z",
116+
"start_time": "2025-11-02T13:09:31.759429Z"
117117
}
118118
},
119119
"source": [
@@ -184,19 +184,19 @@
184184
"</div>"
185185
]
186186
},
187-
"execution_count": 63,
187+
"execution_count": 4,
188188
"metadata": {},
189189
"output_type": "execute_result"
190190
}
191191
],
192-
"execution_count": 63
192+
"execution_count": 4
193193
},
194194
{
195195
"cell_type": "code",
196196
"metadata": {
197197
"ExecuteTime": {
198-
"end_time": "2025-10-30T16:19:55.729968Z",
199-
"start_time": "2025-10-30T16:19:55.716535Z"
198+
"end_time": "2025-11-02T13:09:31.803405Z",
199+
"start_time": "2025-11-02T13:09:31.796959Z"
200200
}
201201
},
202202
"source": [
@@ -227,7 +227,7 @@
227227
]
228228
}
229229
],
230-
"execution_count": 64
230+
"execution_count": 5
231231
},
232232
{
233233
"cell_type": "markdown",
@@ -240,8 +240,8 @@
240240
"cell_type": "code",
241241
"metadata": {
242242
"ExecuteTime": {
243-
"end_time": "2025-10-30T16:19:55.994396Z",
244-
"start_time": "2025-10-30T16:19:55.906651Z"
243+
"end_time": "2025-11-02T13:09:31.971193Z",
244+
"start_time": "2025-11-02T13:09:31.871029Z"
245245
}
246246
},
247247
"source": [
@@ -284,14 +284,14 @@
284284
"output_type": "display_data"
285285
}
286286
],
287-
"execution_count": 65
287+
"execution_count": 6
288288
},
289289
{
290290
"cell_type": "code",
291291
"metadata": {
292292
"ExecuteTime": {
293-
"end_time": "2025-10-30T16:19:56.025546Z",
294-
"start_time": "2025-10-30T16:19:56.022577Z"
293+
"end_time": "2025-11-02T13:09:31.986196Z",
294+
"start_time": "2025-11-02T13:09:31.983898Z"
295295
}
296296
},
297297
"source": [
@@ -326,7 +326,7 @@
326326
]
327327
}
328328
],
329-
"execution_count": 66
329+
"execution_count": 7
330330
},
331331
{
332332
"cell_type": "markdown",
@@ -337,12 +337,24 @@
337337
"**Note**: Replace `base_url` with your actual FAIM inference API endpoint."
338338
]
339339
},
340+
{
341+
"metadata": {
342+
"ExecuteTime": {
343+
"end_time": "2025-11-02T13:09:32.012024Z",
344+
"start_time": "2025-11-02T13:09:32.010425Z"
345+
}
346+
},
347+
"cell_type": "code",
348+
"source": "",
349+
"outputs": [],
350+
"execution_count": null
351+
},
340352
{
341353
"cell_type": "code",
342354
"metadata": {
343355
"ExecuteTime": {
344-
"end_time": "2025-10-30T16:19:56.053034Z",
345-
"start_time": "2025-10-30T16:19:56.043036Z"
356+
"end_time": "2025-11-02T13:09:32.047796Z",
357+
"start_time": "2025-11-02T13:09:32.044621Z"
346358
}
347359
},
348360
"source": [
@@ -351,7 +363,8 @@
351363
"# BASE_URL = \"http://localhost:8003\" # Example: \"https://api.faim.example.com\"\n",
352364
"# BASE_URL = (\"http://34.141.187.117\") # Example: \"https://api.faim.example.com\"\n",
353365
"BASE_URL = (\"https://api.faim.it.com\") # Example: \"https://api.faim.example.com\"\n",
354-
"FAIM_API_KEY = os.environ[\"FAIM_API_KEY\"] # \"your-secret-api-key\"\n",
366+
"# FAIM_API_KEY = os.environ[\"FAIM_API_KEY\"] # \"your-secret-api-key\"\n",
367+
"FAIM_API_KEY = \"api_key_1_28bbe832-bbb3-4444-83bd-06d8615bffbb_6hCNkGmAy4TUgcXD8s71t9ALz39CIxJKksHRKBU-dzM\"\n",
355368
"client = ForecastClient(\n",
356369
" base_url=BASE_URL,\n",
357370
" api_key=FAIM_API_KEY, # Optional: API key for authentication\n",
@@ -367,13 +380,6 @@
367380
" assert False, 'you need to set up your API key'"
368381
],
369382
"outputs": [
370-
{
371-
"name": "stderr",
372-
"output_type": "stream",
373-
"text": [
374-
"INFO:faim_sdk.client:Initialized ForecastClient with authentication: base_url=https://api.faim.it.com, timeout=60.0s\n"
375-
]
376-
},
377383
{
378384
"name": "stdout",
379385
"output_type": "stream",
@@ -383,24 +389,47 @@
383389
]
384390
}
385391
],
386-
"execution_count": 67
392+
"execution_count": 8
387393
},
388394
{
389395
"cell_type": "code",
390396
"metadata": {
391397
"ExecuteTime": {
392-
"end_time": "2025-10-30T16:19:56.105543Z",
393-
"start_time": "2025-10-30T16:19:56.099754Z"
398+
"end_time": "2025-11-02T13:09:32.064134Z",
399+
"start_time": "2025-11-02T13:09:32.062414Z"
394400
}
395401
},
396402
"source": [
397403
"import logging\n",
398404
"\n",
399405
"# Enable debug logging\n",
400-
"logging.basicConfig(level=logging.DEBUG)\n"
406+
"# logging.basicConfig(level=logging.DEBUG)\n"
401407
],
402408
"outputs": [],
403-
"execution_count": 68
409+
"execution_count": 9
410+
},
411+
{
412+
"metadata": {
413+
"ExecuteTime": {
414+
"end_time": "2025-11-02T13:09:32.077835Z",
415+
"start_time": "2025-11-02T13:09:32.075596Z"
416+
}
417+
},
418+
"cell_type": "code",
419+
"source": "x.shape",
420+
"outputs": [
421+
{
422+
"data": {
423+
"text/plain": [
424+
"(1, 250, 1)"
425+
]
426+
},
427+
"execution_count": 10,
428+
"metadata": {},
429+
"output_type": "execute_result"
430+
}
431+
],
432+
"execution_count": 10
404433
},
405434
{
406435
"cell_type": "markdown",
@@ -411,8 +440,8 @@
411440
"cell_type": "code",
412441
"metadata": {
413442
"ExecuteTime": {
414-
"end_time": "2025-10-30T16:19:56.133897Z",
415-
"start_time": "2025-10-30T16:19:56.131085Z"
443+
"end_time": "2025-11-02T13:09:32.091706Z",
444+
"start_time": "2025-11-02T13:09:32.088676Z"
416445
}
417446
},
418447
"source": [
@@ -445,7 +474,7 @@
445474
]
446475
}
447476
],
448-
"execution_count": 69
477+
"execution_count": 11
449478
},
450479
{
451480
"cell_type": "markdown",
@@ -458,8 +487,8 @@
458487
"cell_type": "code",
459488
"metadata": {
460489
"ExecuteTime": {
461-
"end_time": "2025-10-30T16:19:58.648828Z",
462-
"start_time": "2025-10-30T16:19:56.151677Z"
490+
"end_time": "2025-11-02T13:09:32.883338Z",
491+
"start_time": "2025-11-02T13:09:32.114395Z"
463492
}
464493
},
465494
"source": [
@@ -488,50 +517,33 @@
488517
"name": "stderr",
489518
"output_type": "stream",
490519
"text": [
491-
"DEBUG:faim_sdk.client:Starting forecast: model=flowstate, version=1, x.shape=(1, 250, 1), horizon=20\n",
492-
"DEBUG:faim_sdk.client:Serialized request: 1520 bytes, metadata={'horizon': 20, 'output_type': 'point', 'scale_factor': 0.65, 'prediction_type': 'mean'}\n",
493-
"DEBUG:httpcore.connection:connect_tcp.started host='api.faim.it.com' port=443 local_address=None timeout=60.0 socket_options=None\n",
494-
"DEBUG:httpcore.connection:connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x125c7e200>\n",
495-
"DEBUG:httpcore.connection:start_tls.started ssl_context=<ssl.SSLContext object at 0x125c1ba40> server_hostname='api.faim.it.com' timeout=60.0\n",
496-
"DEBUG:httpcore.connection:start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x125c7f250>\n",
497-
"DEBUG:httpcore.http11:send_request_headers.started request=<Request [b'POST']>\n",
498-
"DEBUG:httpcore.http11:send_request_headers.complete\n",
499-
"DEBUG:httpcore.http11:send_request_body.started request=<Request [b'POST']>\n",
500-
"DEBUG:httpcore.http11:send_request_body.complete\n",
501-
"DEBUG:httpcore.http11:receive_response_headers.started request=<Request [b'POST']>\n",
502-
"DEBUG:httpcore.http11:receive_response_headers.complete return_value=(b'HTTP/1.1', 401, b'Unauthorized', [(b'date', b'Thu, 30 Oct 2025 16:19:57 GMT'), (b'server', b'uvicorn'), (b'Content-Length', b'74'), (b'content-type', b'application/json'), (b'Via', b'1.1 google'), (b'Alt-Svc', b'h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000')])\n",
503-
"INFO:httpx:HTTP Request: POST https://api.faim.it.com/v1/ts/forecast/flowstate/1 \"HTTP/1.1 401 Unauthorized\"\n",
504-
"DEBUG:httpcore.http11:receive_response_body.started request=<Request [b'POST']>\n",
505-
"DEBUG:httpcore.http11:receive_response_body.complete\n",
506-
"DEBUG:httpcore.http11:response_closed.started\n",
507-
"DEBUG:httpcore.http11:response_closed.complete\n",
508-
"ERROR:faim_sdk.client:Unexpected status code: 401\n"
520+
"API error: status=401, code=INVALID_API_KEY, message=API key not found or inactive, request_id=<faim_client.types.Unset object at 0x1222da620>\n"
509521
]
510522
},
511523
{
512524
"name": "stdout",
513525
"output_type": "stream",
514526
"text": [
515-
"✗ Forecast failed: Unexpected status code: 401 | status=401\n",
527+
"✗ Forecast failed: API key not found or inactive | status=401 | error_code=INVALID_API_KEY\n",
516528
"\n",
517-
"Error type: APIError\n",
529+
"Error type: AuthenticationError\n",
518530
"Details: {}\n"
519531
]
520532
},
521533
{
522-
"ename": "APIError",
523-
"evalue": "Unexpected status code: 401 | status=401",
534+
"ename": "AuthenticationError",
535+
"evalue": "API key not found or inactive | status=401 | error_code=INVALID_API_KEY",
524536
"output_type": "error",
525537
"traceback": [
526538
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
527-
"\u001B[0;31mAPIError\u001B[0m Traceback (most recent call last)",
528-
"Cell \u001B[0;32mIn[70], line 3\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 2\u001B[0m \u001B[38;5;66;03m# Make forecast request\u001B[39;00m\n\u001B[0;32m----> 3\u001B[0m response \u001B[38;5;241m=\u001B[39m \u001B[43mclient\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mforecast\u001B[49m\u001B[43m(\u001B[49m\u001B[43mModelName\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mFLOWSTATE\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mrequest\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 5\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m✓ Forecast successful!\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 6\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124mResponse: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n",
529-
"File \u001B[0;32m~/Documents/Personal/research/FAIM/faim-client/faim_sdk/client.py:225\u001B[0m, in \u001B[0;36mForecastClient.forecast\u001B[0;34m(self, model, request)\u001B[0m\n\u001B[1;32m 223\u001B[0m \u001B[38;5;28;01melif\u001B[39;00m response\u001B[38;5;241m.\u001B[39mstatus_code \u001B[38;5;241m!=\u001B[39m \u001B[38;5;241m200\u001B[39m:\n\u001B[1;32m 224\u001B[0m logger\u001B[38;5;241m.\u001B[39merror(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mUnexpected status code: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;241m.\u001B[39mstatus_code\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m--> 225\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m APIError(\n\u001B[1;32m 226\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mUnexpected status code: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;241m.\u001B[39mstatus_code\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m,\n\u001B[1;32m 227\u001B[0m status_code\u001B[38;5;241m=\u001B[39mresponse\u001B[38;5;241m.\u001B[39mstatus_code,\n\u001B[1;32m 228\u001B[0m response\u001B[38;5;241m=\u001B[39mresponse\u001B[38;5;241m.\u001B[39mparsed \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mhasattr\u001B[39m(response, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mparsed\u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;28;01melse\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m,\n\u001B[1;32m 229\u001B[0m )\n\u001B[1;32m 231\u001B[0m \u001B[38;5;66;03m# Deserialize successful response\u001B[39;00m\n\u001B[1;32m 232\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n",
530-
"\u001B[0;31mAPIError\u001B[0m: Unexpected status code: 401 | status=401"
539+
"\u001B[0;31mAuthenticationError\u001B[0m Traceback (most recent call last)",
540+
"Cell \u001B[0;32mIn[12], line 3\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 2\u001B[0m \u001B[38;5;66;03m# Make forecast request\u001B[39;00m\n\u001B[0;32m----> 3\u001B[0m response \u001B[38;5;241m=\u001B[39m \u001B[43mclient\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mforecast\u001B[49m\u001B[43m(\u001B[49m\u001B[43mModelName\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mFLOWSTATE\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mrequest\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 5\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m✓ Forecast successful!\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 6\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124mResponse: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n",
541+
"File \u001B[0;32m~/Documents/Personal/research/FAIM/faim-client/faim_sdk/client.py:247\u001B[0m, in \u001B[0;36mForecastClient.forecast\u001B[0;34m(self, model, request)\u001B[0m\n\u001B[1;32m 245\u001B[0m \u001B[38;5;66;03m# Map HTTP status code to exception class\u001B[39;00m\n\u001B[1;32m 246\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m response\u001B[38;5;241m.\u001B[39mstatus_code \u001B[38;5;129;01min\u001B[39;00m (\u001B[38;5;241m401\u001B[39m, \u001B[38;5;241m403\u001B[39m):\n\u001B[0;32m--> 247\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m AuthenticationError(\n\u001B[1;32m 248\u001B[0m message\u001B[38;5;241m=\u001B[39mmessage,\n\u001B[1;32m 249\u001B[0m status_code\u001B[38;5;241m=\u001B[39mresponse\u001B[38;5;241m.\u001B[39mstatus_code,\n\u001B[1;32m 250\u001B[0m error_response\u001B[38;5;241m=\u001B[39merror_response,\n\u001B[1;32m 251\u001B[0m )\n\u001B[1;32m 252\u001B[0m \u001B[38;5;28;01melif\u001B[39;00m response\u001B[38;5;241m.\u001B[39mstatus_code \u001B[38;5;241m==\u001B[39m \u001B[38;5;241m402\u001B[39m:\n\u001B[1;32m 253\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m InsufficientFundsError(\n\u001B[1;32m 254\u001B[0m message\u001B[38;5;241m=\u001B[39mmessage,\n\u001B[1;32m 255\u001B[0m status_code\u001B[38;5;241m=\u001B[39mresponse\u001B[38;5;241m.\u001B[39mstatus_code,\n\u001B[1;32m 256\u001B[0m error_response\u001B[38;5;241m=\u001B[39merror_response,\n\u001B[1;32m 257\u001B[0m )\n",
542+
"\u001B[0;31mAuthenticationError\u001B[0m: API key not found or inactive | status=401 | error_code=INVALID_API_KEY"
531543
]
532544
}
533545
],
534-
"execution_count": 70
546+
"execution_count": 12
535547
},
536548
{
537549
"cell_type": "markdown",

0 commit comments

Comments
 (0)