Flutter ChatGPT API Example

You are currently viewing Flutter ChatGPT API Example
flutter chatgpt

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)

⚠️ Be Careful!

  • Your user-agent and IP addressmust 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


flutter chatgpt


  flutter_chatgpt_api: ^1.0.0


import 'package:flutter_chatgpt_api/flutter_chatgpt_api.dart';

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

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

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

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


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)
chatgpt cookie
chatgpt cookie

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

See also  ChatGPT AI App in Flutter

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';


See also  Flutter AI Voice Assistant via ChatGPT AI


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 

Post Credit

This project is developed by coskuncay
Download this project from the below link.
You can visit original source page from the below link:

Spread the love

Leave a Reply