1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ターミナルからGeminiに話しかける(curl)

Last updated at Posted at 2025-05-30

APIキーを取得

image.png

gemini.sh

#!/bin/sh

GEMINI_API_KEY="AIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

curl -s "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=$GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "'$1'"
          }
        ]
      }
    ]
}' | jq -r '.candidates[].content.parts[].text | gsub("\\\\n";"\n")'
  • "\n"を改行コードに置換しています。

使い方

sh gemini.sh 今日の天気

image.png

数秒で応答が返ってきます。

API ライブラリ

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?