llm-gemini

repository·main·Indexed 19 days ago

https://github.com/simonw/llm-gemini

A plugin for the LLM CLI that provides API access to Google's Gemini family of models. It supports multi-modal inputs (images, audio, video, and YouTube), code execution, Google Search grounding, embeddings, and JSON output forcing.

Tokens
1.4K
Snippets
9
Records
11
Agent score
16%

What's inside llm-gemini

  1. Set request timeouts

    main

    You can prevent requests from hanging indefinitely using the timeout option.

    CLI usage:

    llm -m gemini-flash-latest 'prompt' -o timeout 1.5

    Python usage: When using the llm library, pass the timeout parameter to model.prompt(). This raises an httpx.TimeoutException if exceeded.

    import httpx, llm
    
    model = llm.get_model("gemini/gemini-flash-latest")
    
    try:
        response = model.prompt("epic saga about mice", timeout=1.5)
        print(response.text())
    except httpx.TimeoutException:
        print("Timeout exceeded")
  2. Configure the Gemini API key

    main

    You must provide a Google Gemini API key to use the plugin. You can configure it using the llm keys set command or by setting the LLM_GEMINI_KEY environment variable.

    To set it via the CLI:

    1. Run llm keys set gemini.
    2. Paste your API key when prompted.
    llm keys set gemini
  3. Provide multi-modal inputs (Images, Audio, Video, YouTube)

    main

    Gemini models support multi-modal prompting. Use the -a flag to attach files or URLs.

    Images:

    llm -m gemini-flash-latest 'extract text' -a image.jpg
    llm -m gemini-flash-latest 'describe image' -a https://example.com/image.jpg

    Audio:

    llm -m gemini-flash-latest 'transcribe audio' -a audio.mp3

    Video:

    llm -m gemini-flash-latest 'describe what happens' -a video.mp4

    YouTube Videos:

    llm -m gemini-flash-latest -a 'https://www.youtube.com/watch?v=VIDEO_ID' 'Summarize this video'

    Note on YouTube resolution: YouTube videos are processed with low resolution by default. Use -o media_resolution X where X is medium, high, or unspecified to change this.

    llm -m gemini-flash-latest -a 'https://www.youtube.com/watch?v=9o1_DL9uNlM' 'Produce a summary...'
  4. Use Gemini models via the CLI

    main

    Run prompts against Gemini models using the -m flag to specify the model ID. You can also set a default model to avoid specifying it every time.

    Basic usage:

    llm -m gemini-flash-latest "Your prompt here"

    Set a default model:

    llm models default gemini-flash-latest
    llm "Your prompt here"
    llm -m gemini-flash-latest "A short joke about a pelican and a walrus"
  5. Generate and search embeddings

    main

    The plugin supports Gemini embedding models. You can generate embeddings for single strings or bulk-embed files into a SQLite database.

    Single string embedding:

    llm embed -m gemini-embedding-2 -c 'hello world'

    Bulk embedding files: Use embed-multi to embed files into a collection in a SQLite database.

    llm embed-multi readmes -d embed.db -m gemini-embedding-2-768 --files . '*/README.md'

    Similarity search:

    llm similar readmes -c 'upload csvs to stuff' -d embed.db

    Model variants: You can request specific vector dimensions by appending a suffix to the model ID:

    • gemini-embedding-2-768 (768 dimensions)
    • gemini-embedding-2-1536 (1536 dimensions)
    • gemini-embedding-2 (3072 dimensions - default)
  6. Enable Gemini server-side tools (Code Execution, Google Search, URL Context)

    main

    You can enable specific server-side capabilities using the -T flag.

    Code Execution: Allows the model to write and execute Python code in a sandbox.

    llm -m gemini-3.6-flash -T CodeExecution 'use python to calculate (factorial of 13) * 3'

    Google Search: Enables Grounding with Google Search.

    llm -m gemini-3.6-flash -T GoogleSearch 'What happened in Ireland today?'

    Note: To inspect grounding metadata, run llm logs -c --json after the prompt.

    URL Context: Allows the model to fetch content from URLs.

    llm -m gemini-2.5-flash -T URLContext 'Latest headline on simonwillison.net'

    Note: Use --usage to see token counts for tool use.

  7. Available Gemini models

    main

    The plugin provides access to various Gemini and Gemma models. You can use the full ID (e.g., gemini/gemini-3.5-flash) or the shorter alias (e.g., gemini-3.5-flash).

    To see all available models via the plugin, run:

    llm gemini models

    Commonly used models include:

    • gemini-flash-latest (Latest Gemini Flash)
    • gemini-3.5-flash (Gemini 3.5 Flash)
    • gemini-3.5-flash-lite (Gemini 3.5 Flash Lite)
    • gemma-4-31b-it (Gemma 4 31B Instruct)
    • gemini-embedding-2 (Latest embedding model)
  8. List Gemini API models with filters

    main

    Use llm gemini models to list models exposed by the Gemini API. You can filter by supported generation methods using the --method flag.

    Filter by method:

    llm gemini models --method embedContent