{"id":25052104,"url":"https://github.com/gemini-api-php/laravel","last_synced_at":"2025-04-09T21:23:22.442Z","repository":{"id":213903695,"uuid":"735179861","full_name":"gemini-api-php/laravel","owner":"gemini-api-php","description":"Google Gemini API client for Laravel","archived":false,"fork":false,"pushed_at":"2024-08-20T08:10:53.000Z","size":228,"stargazers_count":87,"open_issues_count":10,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T19:08:49.305Z","etag":null,"topics":["gemini","gemini-api","google-gemini","google-generative-ai","laravel","laravel-package"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gemini-api-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-12-24T00:22:03.000Z","updated_at":"2025-03-26T00:44:44.000Z","dependencies_parsed_at":"2024-01-18T23:43:37.016Z","dependency_job_id":null,"html_url":"https://github.com/gemini-api-php/laravel","commit_stats":null,"previous_names":["gemini-api-php/laravel"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gemini-api-php%2Flaravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gemini-api-php%2Flaravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gemini-api-php%2Flaravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gemini-api-php%2Flaravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gemini-api-php","download_url":"https://codeload.github.com/gemini-api-php/laravel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248113104,"owners_count":21049783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gemini","gemini-api","google-gemini","google-generative-ai","laravel","laravel-package"],"created_at":"2025-02-06T10:21:25.099Z","updated_at":"2025-04-09T21:23:22.421Z","avatar_url":"https://github.com/gemini-api-php.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/gemini-api-php/laravel/main/assets/example.png\" width=\"800\" alt=\"Gemini API Client for Laravel - Examples\"\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/gemini-api-php/laravel\"\u003e\u003cimg alt=\"Total Downloads\" src=\"https://img.shields.io/packagist/dt/gemini-api-php/laravel\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/gemini-api-php/laravel\"\u003e\u003cimg alt=\"Latest Version\" src=\"https://img.shields.io/packagist/v/gemini-api-php/laravel\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/gemini-api-php/laravel\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/gemini-api-php/laravel\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# Gemini API Client for Laravel\n\nGemini API Client for Laravel allows you to use the Google's generative AI models, like Gemini Pro and Gemini Pro Vision in your Laravel application.\n\nSupports PHP 8.1 and Laravel v9, v10.\n\n_This library is not developed or endorsed by Google._\n\n- Erdem Köse - **[github.com/erdemkose](https://github.com/erdemkose)**\n\n## Table of Contents\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [How to use](#how-to-use)\n    - [Text Generation](#text-generation)\n    - [Text Generation using Image File](#text-generation-using-image-file)\n    - [Text Generation using Image Data](#text-generation-using-image-data)\n    - [Chat Session (Multi-Turn Conversations)](#chat-session-multi-turn-conversations)\n    - [Chat Session with History](#chat-session-with-history)\n    - [Text Embeddings](#text-embeddings)\n    - [Tokens counting](#tokens-counting)\n    - [Listing models](#listing-models)\n    - [Accessing the underlying Gemini API client](#accessing-the-underlying-gemini-api-client)\n- [Credits](#credits)\n\n## Installation\n\n\u003e You need an API key to gain access to Google's Gemini API.\n\u003e Visit [Google AI Studio](https://makersuite.google.com/) to get an API key.\n\nFirst step is to install the Gemini API Client for Laravel with Composer.\n\n```shell\ncomposer require gemini-api-php/laravel\n```\n\n## Configuration\n\nThere are two ways to configure the client. \n\n### Environment variables\n\nYou can set the `GEMINI_API_KEY` environment variable with the API key you obtained from Google AI studio.\n\nAdd the following line into your `.env` file.\n\n```shell\nGEMINI_API_KEY='YOUR_GEMINI_API_KEY'\n```\n\n### Configuration file\n\nYou can also run the following command to create a configuration file in your applications config folder.\n\n```shell\nphp artisan vendor:publish --provider=GeminiAPI\\Laravel\\ServiceProvider\n```\n\nNow you can edit the `config/gemini.php` file to configure the Gemini API client.\n\n## How to use\n\n### Text Generation\n\n```php\nuse GeminiAPI\\Laravel\\Facades\\Gemini;\n\nprint Gemini::generateText('PHP in less than 100 chars');\n// PHP: A server-side scripting language used to create dynamic web applications.\n// Easy to learn, widely used, and open-source.\n```\n\n### Text Generation Using Image File\n\n```php\nuse GeminiAPI\\Laravel\\Facades\\Gemini;\n\nprint Gemini::generateTextUsingImageFile(\n    'image/jpeg',\n    'elephpant.jpg',\n    'Explain what is in the image',\n);\n// The image shows an elephant standing on the Earth.\n// The elephant is made of metal and has a glowing symbol on its forehead.\n// The Earth is surrounded by a network of glowing lines.\n// The image is set against a starry background.\n```\n\n### Text Generation Using Image Data\n\n```php\nuse GeminiAPI\\Laravel\\Facades\\Gemini;\n\nprint Gemini::generateTextUsingImage(\n    'image/jpeg',\n    base64_encode(file_get_contents('elephpant.jpg')),\n    'Explain what is in the image',\n);\n// The image shows an elephant standing on the Earth.\n// The elephant is made of metal and has a glowing symbol on its forehead.\n// The Earth is surrounded by a network of glowing lines.\n// The image is set against a starry background.\n```\n\n### Chat Session (Multi-Turn Conversations)\n\n```php\nuse GeminiAPI\\Laravel\\Facades\\Gemini;\n\n$chat = Gemini::startChat();\n\nprint $chat-\u003esendMessage('Hello World in PHP');\n// echo \"Hello World!\";\n// This code will print \"Hello World!\" to the standard output.\n\nprint $chat-\u003esendMessage('in Go');\n// fmt.Println(\"Hello World!\")\n// This code will print \"Hello World!\" to the standard output.\n```\n\n### Chat Session with History\n\n```php\nuse GeminiAPI\\Laravel\\Facades\\Gemini;\n\n$history = [\n    [\n        'message' =\u003e 'Hello World in PHP',\n        'role' =\u003e 'user',\n    ],\n    [\n        'message' =\u003e \u003c\u003c\u003cMESSAGE\n            echo \"Hello World!\";\n\n            This code will print \"Hello World!\" to the standard output.\n            MESSAGE,\n        'role' =\u003e 'model',\n    ],\n];\n$chat = Gemini::startChat($history);\n\nprint $chat-\u003esendMessage('in Go');\n// fmt.Println(\"Hello World!\")\n// This code will print \"Hello World!\" to the standard output.\n```\n\n### Text Embeddings\n\n```php\nuse GeminiAPI\\Laravel\\Facades\\Gemini;\n\nprint_r(Gemini::embedText('PHP in less than 100 chars'));\n// [\n//    [0] =\u003e 0.041395925\n//    [1] =\u003e -0.017692696\n//    ...\n// ]\n```\n\n### Tokens counting\n\n```php\nuse GeminiAPI\\Laravel\\Facades\\Gemini;\n\nprint Gemini::countTokens('PHP in less than 100 chars');\n// 10\n```\n\n### Listing models\n\n```php\nuse GeminiAPI\\Laravel\\Facades\\Gemini;\n\nprint_r(Gemini::listModels());\n//[\n//  [0] =\u003e GeminiAPI\\Resources\\Model Object\n//    (\n//      [name] =\u003e models/gemini-pro\n//      [displayName] =\u003e Gemini Pro\n//      [description] =\u003e The best model for scaling across a wide range of tasks\n//      ...\n//    )\n//  [1] =\u003e GeminiAPI\\Resources\\Model Object\n//    (\n//      [name] =\u003e models/gemini-pro-vision\n//      [displayName] =\u003e Gemini Pro Vision\n//      [description] =\u003e The best image understanding model to handle a broad range of applications\n//      ...\n//    )\n//]\n```\n\n### Accessing the underlying Gemini API client\n\n```php\nuse GeminiAPI\\Laravel\\Facades\\Gemini;\n\n$client = Gemini::client();\n```\n\n## Credits\n\nThis project was inspired by the great work of [OpenAI PHP for Laravel](https://github.com/openai-php/laravel) and [OpenAI PHP client](https://github.com/openai-php/client).\n\nWe gratefully acknowledge the contributions of [OpenAI PHP](https://github.com/openai-php) and its team.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgemini-api-php%2Flaravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgemini-api-php%2Flaravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgemini-api-php%2Flaravel/lists"}