Skip to content

Conversation

@cestercian
Copy link

This PR adds token counting functionality to the Go API examples, following the structure of the JavaScript and Python implementations. It demonstrates token counting for various content types using the Gemini API.

Changes

  • Added count_tokens.go with implementations for:
    • Text-only token counting
    • Chat history token counting
    • Multimodal content (images, video, PDFs)
    • System instruction token counting
  • Added count_tokens_test.go with test cases

Implementation Details

  • Follows the same structure and documentation style as JS and Python examples
  • Maintains region markers for documentation generation
  • Includes proper error handling and Go best practices
  • Ensures correct copyright headers and license information

Testing

  • Validates token counts are greater than zero
  • Confirms usage metadata contains valid values
  • Checks combined token counts exceed individual counts where applicable

This provides a reference for developers using the Go SDK to understand token usage with the Gemini API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant