As of mid-day May 2, the endpoint https://generativelanguage.googleapis.com/v1beta/ appends this object to server responses after the “candidates” array:
"usageMetadata": {
"candidatesTokenCount": 27
}
This post has the bug tag because that means the messages returned from the endpoint no longer conform to the specification for GenerateContentResponse
This change broke application code, for example the go library started showing
proto: (line 34:3): unknown field "usageMetadata"
(This is reported in https://github.com/google/generative-ai-go/issues/97 )
Two questions:
- Is the new observed behavior a permanent change, and the documentation for
GenerateContentResponsewill be updated soon? - The specification for
Candidate(Generating content | Gemini API | Google AI for Developers) includes the member “tokenCount”: integer, which has been missing in the responses from the v1beta endpoint (this has been previously reported and is a known bug). Based on its placement, we are currently assuming thatcandidatesTokenCount(inusageMetadata) will contain the sum of thetokenCountover the array ofCandidate. Since the candidate count is currently fixed at 1, thecandidatesTokenCountmay be a suitable substitute for the missingtokenCountfield. Is that the intention?
Receiving a response from an authoritative source is valuable for developers using the API.