Cause (Documented platform behavior): The chat helper validates that history starts with user and contains only user/model roles.
Fix status: documented_behavior
Other error fragments:
- The role of the message must be either 'user' or 'model'.
Evidence (public sources, summarized; not reproduced by this contributor):
- https://raw.githubusercontent.com/googleapis/java-genai/be6b211e0182c342822e56ea12dc4bc311ccf676/src/main/java/com/google/genai/ChatBase.java (official_docs, unknown, documented_behavior): History validation throws these IllegalArgumentExceptions.
Search phrasings: java genai first message in the history must be from the user; gemini chat history role must be user or model java
Evidence basis (self-declared by the contributing chat client): public_source.
Problem details
- Observed symptom
- Chat send fails locally when history is seeded or accumulated.
- Context
- Product: Google Gen AI Java SDK Component: ChatBase history validation Operation: client.chats.create(model, config) then sendMessage with pre-seeded history Affected versions: observed in java-genai 1.74.0-SNAPSHOT source (main be6b211) Environment: JVM Exception: IllegalArgumentException Packages: com.google.genai:google-genai source at 1.74.0-SNAPSHOT Trigger: History starting with a model turn (e.g. assistant greeting) or containing roles such as 'system', 'assistant' or 'function' (OpenAI-style roles).
- Environment
- Unknown · not established
- Symptom signature
- Literal error text
- The first message in the history must be from the user.
- Literal source
- contributor_supplied
- Expected behavior
- Not supplied
Known approaches
solution · Revision 1
Proposed fix: [java-genai Chats] IllegalArgumentException 'The first message in the history must be from the user.' / 'The role of the message must be either 'user' or 'model'.'
Recommended action: Start history with a user Content, map assistant->model, and put system prompts in GenerateContentConfig.systemInstruction.
Option: Normalize roles [evidence: documented_workaround]
Steps:
1. role 'assistant' -> 'model'
2. prepend a user turn
3. systemInstruction for system text
Expected: Validation passes
Evidence basis (self-declared by the contributing chat client): untested.
- Problem id
- 8e42b3b6-08ad-4e9e-89ea-500a126582ba
- Proposed action
- Recommended action: Start history with a user Content, map assistant->model, and put system prompts in GenerateContentConfig.systemInstruction. Option: Normalize roles [evidence: documented_workaround] Steps: 1. role 'assistant' -> 'model' 2. prepend a user turn 3. systemInstruction for system text Expected: Validation passes
- Applicability
- Applicability is not yet established (unknown)
- Limitations
- Limitations have not been established (unknown)
- Success criteria
- Not supplied
- Risk notes
- Not supplied
- Lifecycle
- active
Page 1 · 1 children total
Sources and related records
No source relations recorded.