#!/bin/bash # Session Continuity Example with curl # This script demonstrates how to use session continuity with the Claude Code OpenAI API Wrapper echo "๐Ÿš€ Claude Code Session Continuity - curl Example" echo "=================================================" BASE_URL="http://localhost:8000" SESSION_ID="curl-demo-session" # Check server health echo "๐Ÿ“‹ Checking server health..." curl -s "$BASE_URL/health" | jq . echo "" # First message - introduce context echo "1๏ธโƒฃ First message (introducing context):" echo "Request: Hello! I'm Sarah and I'm learning React." curl -s -X POST "$BASE_URL/v1/chat/completions" \ -H "Content-Type: application/json" \ -d "{ \"model\": \"claude-3-5-sonnet-20241022\", \"messages\": [ {\"role\": \"user\", \"content\": \"Hello! I'm Sarah and I'm learning React.\"} ], \"session_id\": \"$SESSION_ID\" }" | jq -r '.choices[0].message.content' echo "" # Second message - test memory echo "2๏ธโƒฃ Second message (testing memory):" echo "Request: What's my name and what am I learning?" curl -s -X POST "$BASE_URL/v1/chat/completions" \ -H "Content-Type: application/json" \ -d "{ \"model\": \"claude-3-5-sonnet-20241022\", \"messages\": [ {\"role\": \"user\", \"content\": \"What's my name and what am I learning?\"} ], \"session_id\": \"$SESSION_ID\" }" | jq -r '.choices[0].message.content' echo "" # Third message - continue conversation echo "3๏ธโƒฃ Third message (building on context):" echo "Request: Can you suggest a simple React project for me?" curl -s -X POST "$BASE_URL/v1/chat/completions" \ -H "Content-Type: application/json" \ -d "{ \"model\": \"claude-3-5-sonnet-20241022\", \"messages\": [ {\"role\": \"user\", \"content\": \"Can you suggest a simple React project for me?\"} ], \"session_id\": \"$SESSION_ID\" }" | jq -r '.choices[0].message.content' echo "" # Session management examples echo "๐Ÿ›  Session Management Examples" echo "================================" # List sessions echo "๐Ÿ“‹ List all sessions:" curl -s "$BASE_URL/v1/sessions" | jq . echo "" # Get specific session info echo "๐Ÿ” Get session info:" curl -s "$BASE_URL/v1/sessions/$SESSION_ID" | jq . echo "" # Get session stats echo "๐Ÿ“Š Session statistics:" curl -s "$BASE_URL/v1/sessions/stats" | jq . echo "" # Streaming example with session echo "๐ŸŒŠ Streaming with session continuity:" echo "Request: Thanks for your help!" curl -s -X POST "$BASE_URL/v1/chat/completions" \ -H "Content-Type: application/json" \ -d "{ \"model\": \"claude-3-5-sonnet-20241022\", \"messages\": [ {\"role\": \"user\", \"content\": \"Thanks for your help!\"} ], \"session_id\": \"$SESSION_ID\", \"stream\": true }" | grep '^data: ' | head -5 | jq -r '.choices[0].delta.content // empty' 2>/dev/null | tr -d '\n' echo "" echo "" # Delete session echo "๐Ÿงน Cleaning up session:" curl -s -X DELETE "$BASE_URL/v1/sessions/$SESSION_ID" | jq . echo "" echo "โœจ curl session example complete!" echo "" echo "๐Ÿ’ก Key Points:" echo " โ€ข Include \"session_id\": \"your-session-id\" in request body" echo " โ€ข Same session_id maintains conversation context" echo " โ€ข Works with both streaming and non-streaming requests" echo " โ€ข Use session management endpoints to monitor and control sessions" echo " โ€ข Sessions auto-expire after 1 hour of inactivity"