diff --git a/cookbook/example_multi_modal_traces.ipynb b/cookbook/example_multi_modal_traces.ipynb index 78706e60..fb5483b2 100644 --- a/cookbook/example_multi_modal_traces.ipynb +++ b/cookbook/example_multi_modal_traces.ipynb @@ -345,6 +345,13 @@ "## Custom via API" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[Link to API docs](https://api.reference.langfuse.com/#tag--Media)" + ] + }, { "cell_type": "markdown", "metadata": { @@ -499,6 +506,36 @@ " print(\"File uploaded\")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Update upload status" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from datetime import datetime, timezone\n", + "\n", + "if upload_response is not None:\n", + " requests.patch(\n", + " f\"{base_URL}/api/public/media/{upload_url_response['mediaId']}\",\n", + " auth=(public_key or \"\", secret_key or \"\"),\n", + " headers={\"Content-Type\": \"application/json\"},\n", + " json={\n", + " \"uploadedAt\": datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.%fZ'), # ISO 8601\n", + " \"uploadHttpStatus\": upload_response.status_code,\n", + " \"uploadHttpError\": upload_response.text if upload_response.status_code != 200 else None,\n", + " },\n", + " )\n", + "\n", + " print(\"Upload status updated\")" + ] + }, { "cell_type": "markdown", "metadata": { diff --git a/pages/guides/cookbook/example_multi_modal_traces.md b/pages/guides/cookbook/example_multi_modal_traces.md index 2c885923..bf9c0add 100644 --- a/pages/guides/cookbook/example_multi_modal_traces.md +++ b/pages/guides/cookbook/example_multi_modal_traces.md @@ -206,6 +206,8 @@ handler.flush() ## Custom via API +[Link to API docs](https://api.reference.langfuse.com/#tag--Media) + ### Setup @@ -298,6 +300,27 @@ if ( print("File uploaded") ``` +### Update upload status + + +```python +from datetime import datetime, timezone + +if upload_response is not None: + requests.patch( + f"{base_URL}/api/public/media/{upload_url_response['mediaId']}", + auth=(public_key or "", secret_key or ""), + headers={"Content-Type": "application/json"}, + json={ + "uploadedAt": datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.%fZ'), # ISO 8601 + "uploadHttpStatus": upload_response.status_code, + "uploadHttpError": upload_response.text if upload_response.status_code != 200 else None, + }, + ) + + print("Upload status updated") +``` + ### Fetch media link