Search packages, repositories and app categories

Package detailsv1.1.0

flutter_chatgpt_api

Flutter/Dart API around ChatGPT for the unofficial ChatGPT API.

AndroidiOSmacOSWindowsLinux
30-day downloads
93
Likes
100
Pub points
130

Install package

flutter pub add flutter_chatgpt_api

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Flutter/Dart package that provides a simple API wrapper for the unofficial ChatGPT API, enabling developers to integrate ChatGPT functionality into their Flutter applications. It supports multiple platforms including Android, iOS, macOS, Windows, and Linux. The package abstracts low-level HTTP interactions, offering an easy-to-use interface for sending messages and receiving responses from ChatGPT. Ideal for apps requiring conversational AI features without relying on official APIs.

Use cases

  • Integrating chatbots into mobile apps
  • Building AI-powered customer support tools
  • Creating interactive learning applications
  • Enabling real-time text generation in apps

Key features

  • Unofficial ChatGPT API integration
  • Cross-platform support
  • Simple synchronous and async message handling
  • Built-in error handling
  • Lightweight and easy to set up

Suitable for

  • Developers building AI chat features
  • Prototyping generative AI applications
  • Apps needing quick access to ChatGPT-like responses

Considerations

  • Relies on unofficial API (may be unstable or discontinued)
  • No official Google/Apple approval
  • Rate limits and potential IP blocking
  • Requires valid authentication tokens

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Flutter ChatGPT API

This package is a Flutter/Dart API around ChatGPT by OpenAI.

This package requires a valid session token from ChatGPT to access its unofficial REST API.

This version have been updated to use Puppeteer to log in to ChatGPT and extract the Cloudflare cf_clearance cookie and OpenAI session token. 🔥 Thanks to Node.js ChatGPT API (unofficial)

:warning: Be Careful!

  • Your user-agent and IP address must match from the real browser window you're logged in with to the one you're using for ChatGPTAPI.
    • This means that you currently can't log in with your laptop and then run the bot on a server or proxy somewhere.
  • Please check defaultHeaders

Demo

Installation

dependencies:
  flutter_chatgpt_api: ^1.0.0

Usage


import 'package:flutter_chatgpt_api/flutter_chatgpt_api.dart';

 _api = ChatGPTApi(
       sessionToken: SESSION_TOKEN,
       clearanceToken: CLEARANCE_TOKEN,
     );

setState(() {
  _messages.add(
    ChatMessage(
      text: _textController.text,
      chatMessageType: ChatMessageType.user,
    ),
  );
  isLoading = true;
});  

var newMessage = await _api.sendMessage(
  input,
  conversationId: _conversationId,
  parentMessageId: _parentMessageId,
);

setState(() {
  _conversationId = newMessage.conversationId;
  _parentMessageId = newMessage.messageId;
  isLoading = false;
  _messages.add(
    ChatMessage(
      text: newMessage.message,
      chatMessageType: ChatMessageType.bot,
    ),
  );
});

SessionToken

To get a session token:

  1. Go to https://chat.openai.com/chat and log in or sign up.
  2. Open dev tools.
  3. Open Application > Cookies (Storage > Cookies)

image

  1. Create these files and add your session token to run the tests and example respectively:

Copy the value for __Secure-next-auth.session-token and save it to your environment.example/lib/session_token.dart

Copy the value for cf_clearance and save it to your environment. example/lib/clearance_token.dart

Should look something like this:

const SESSION_TOKEN = '__Secure-next-auth.session-token from https://chat.openai.com/chat';
const CLEARANCE_TOKEN = 'cf_clearance token from https://chat.openai.com/chat';

Credit

License

MIT Copyright (c) 2022, Emre Coşkunçay

If you found this project interesting, please consider supporting my open source work by sponsoring me or following me on twitter twitter

Categories

Dependencies

Dependency list 2 items

Source repository

Projects using this package

No data available yet.