Sessions

Sessions store conversation history for multi-turn interactions. Each session is created automatically when a /chat or /code request completes, and the session ID is returned in the done SSE event.

Sessions are stored in Redis and encrypted at rest using Fernet symmetric encryption. They are not persisted to Firestore.


GET /session/{id}/history

Retrieve the full message history for a session.

GET /session/{id}/history

Authentication

Requires one of:

  • X-Api-Key header with a valid API key

  • Authorization and X-Firebase-AppCheck headers for browser-based auth

Users can only access their own sessions.

Path Parameters

Parameter
Type
Required
Description

id

string

Yes

The session ID returned in the done event from /chat or /code.

Request Example

curl -X GET https://inference-api-611798501438.us-central1.run.app/session/abc123/history \
  -H "X-Api-Key: inf_your_api_key_here"

Response

Returns the ordered array of messages in the session.

Response Fields

Field
Type
Description

session_id

string

The unique session identifier.

messages

array

Ordered array of message objects with role and content fields.

model

string

The model ID used in this session.

created_at

string

ISO 8601 timestamp of session creation.

updated_at

string

ISO 8601 timestamp of the last message added.

Error Responses

Status
Description

401

Missing or invalid authentication

403

Session belongs to a different user

404

Session not found or expired

500

Internal server error


DELETE /session/{id}

Delete a session and its entire conversation history.

Authentication

Requires one of:

  • X-Api-Key header with a valid API key

  • Authorization and X-Firebase-AppCheck headers for browser-based auth

Users can only delete their own sessions.

Path Parameters

Parameter
Type
Required
Description

id

string

Yes

The session ID to delete.

Request Example

Response

Returns a confirmation of deletion.

Error Responses

Status
Description

401

Missing or invalid authentication

403

Session belongs to a different user

404

Session not found or already deleted

500

Internal server error


Session Lifecycle

  1. Creation: A session is created automatically when a /chat or /code request completes. The session_id is included in the done SSE event.

  2. Continuation: Pass the session_id in subsequent /chat or /code requests to continue the conversation. The server appends new messages to the existing history.

  3. Storage: Sessions are stored in Redis and encrypted with Fernet symmetric encryption. They are ephemeral and subject to Redis eviction policies.

  4. Deletion: Sessions can be explicitly deleted via DELETE /session/{id}, or they expire based on the configured Redis TTL.

Important: Because sessions are stored in Redis (not a persistent database), they may be lost during infrastructure maintenance or scaling events. Clients should not rely on sessions as permanent storage.

Last updated