Skip to content

mzyui/poe-api-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

66 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Poe API Rust

A simple, lightweight, and efficient API wrapper for Poe.com

Table of Contents ๐Ÿ“š


Overview โœจ

Poe API Rust is a high-performance API designed to manage chat and messaging functionalities on Poe.com. Leveraging the safety and concurrency benefits of Rust, this API wrapper enables you to:

  • Explore available users, bots, and AI models.
  • Customize chat conversation settings.
  • Send, retry, and cancel messages seamlessly.
  • Retrieve detailed data about bots and users.
  • Optimize chat contexts for enhanced interactions.

This documentation provides a comprehensive guide to all the available functions within the API.

Installation ๐Ÿ’พ

Use Cargo to manage your dependencies and build your project. To integrate the API, add the following dependency to your Cargo.toml:

[dependencies]
poe-api = { git = "https://github.com/zevtyardt/poe-api-rust", default-features = false }
Command-Line Interface (CLI)

This library also offers a CLI. Install it using:

cargo install --git "https://github.com/zevtyardt/poe-api-rust"

Then, execute CLI commands using the poe-cli command.


Documentation ๐Ÿ“–

How to Get Your Token ๐Ÿ”‘

Step 1: Retrieve p-b and p-lat Cookies (Required)

  1. Sign in at poe.com.
  2. Open Developer Tools:
    • Chromium: Press F12 or right-click and select Inspect, then navigate to Application > Cookies > poe.com.
    • Firefox: Press F12 or right-click and select Inspect, then go to Storage > Cookies.
    • Safari: Press F12 or right-click and select Inspect, then access Storage > Cookies.
  3. Copy the values of the p-b and p-lat cookies.

Step 2: Retrieve formkey (Optional)

Note: The poe-api-rust automatically retrieves the formkey for you. If this fails, follow the steps below to obtain the token manually.

There are two methods to get the formkey:

  1. Method 1: Using the Network Tab

    • Open Developer Tools (F12 or right-click and select Inspect).
    • Navigate to Network > gql_POST > Headers.
    • Copy the value of Poe-Formkey.
  2. Method 2: Using the Console

    • Open Developer Tools (F12 or right-click and select Inspect).
    • Go to the Console tab.
    • Type: allow pasting and press Enter.
    • Paste the following script:
      window.ereNdsRqhp2Rd3LEW()
    • Copy the resulting output.

Connecting to the API ๐Ÿ”—

Below is a simple example of how to initialize a connection:

use poe_api::{api::PoeApi, models::Token};

let api = PoeApi::new(Token {
    p_b: "P-B", // required
    p_lat: "P-LAT", // required
    formkey: Some("fromkey"), // optional
}).await?;

Send Message โœ‰๏ธ

Send a new message to a specified AI model or bot name. Both text and media messages are supported.

Parameters
pub struct SendMessageData<'a> {
    pub bot_handle: &'a str,
    pub message: &'a str,
    pub chat_id: Option<i64>,
    pub files: Vec<FileInput<'a>>,
}

pub enum FileInput<'a> {
    Url(&'a str),
    Local(PathBuf),
}
Example
use poe_api::models::{SendMessageData, FileInput};
use futures_util::StreamExt;

// Ask a simple question using the "gemini-2.0-flash" model.
let mut message = api.send_message(SendMessageData {
    bot_handle: "gemini-2.0-flash",
    message: "What is the result of 2x2?",
    ..Default::default()
}).await?;

// Handle streamed output.
while let Some(chunk) = message.next().await {
    // Process the chunk or print it directly.
    chunk.print()?;
}

// For non-streamed output:
let text = message.text().await;

Another Example:

Sending a message in an existing chat thread including an image referenced locally:

// Retrieve chat_id from an existing message.
let chat_id = message.chat().inner.chat_id;
let message_data = SendMessageData {
    bot_handle: "gemini-2.0-flash",
    message: "Who is she?",
    chat_id: Some(chat_id),
    files: vec![
        FileInput::Local("my-wife.png")
    ],
};

let mut message = api.send_message(message_data).await?;
// Alternatively:
let mut message = message.chat().send_message(message_data).await?;

println!("{}", message.text().await);

Expected Output:

The anime character in the image is Ritsu Tainaka from the anime series K-On!. She is the self-proclaimed president of the Light Music Club and the drummer of the band Ho-kago Tea Time.

---

Related searches:
+ [anime characters in image](https://www.google.com/search?q=anime+characters+in+image&client=app-vertex-grounding-quora-poe)
+ [anime with characters Ritsu Tainaka](https://www.google.com/search?q=anime+with+characters+Ritsu+Tainaka&client=app-vertex-grounding-quora-poe)

Retry Message ๐Ÿ”„

Reattempt sending or recreating a message that was previously undelivered or inappropriate.

Parameters
Field Name Data Type Description
chat_code &str Chat identifier
Example
let chat_code: &str = "sample";
let mut message = api.retry_message(chat_code).await?;

// Alternately, retry via the message instance.
let message = message.retry().await?;

// Functionality similar to send_message.

Cancel Message โŒ

Cancel a message that is in the process of being sent to avoid duplicates or errors.

Parameters
Field Name Data Type Description
chat_id i64 Chat identifier
Example
let chat_id: i64 = 12345;
api.cancel_message(chat_id).await?;

// Alternately, cancel via the message instance.
message.cancel().await?;

Delete Messages ๐Ÿ—‘๏ธ

Delete one or more messages from a chat by specifying their message IDs.

Parameters
Field Name Data Type Description
chat_id i64 Chat identifier
message_ids Vec<i64> Vector containing message IDs
Example
let chat_id: i64 = 12345;
let message_ids: Vec<i64> = vec![678910, 11121314];
api.delete_message(chat_id, message_ids).await?;

// Delete specific message types:
message.delete_user_message().await?;
message.delete_bot_message().await?;
// Or clear both contexts:
message.delete_message_context().await?;

Get Message Share URL ๐Ÿ”—

Generate a shareable URL for a specific message, making it easy to share externally.

Parameters
Field Name Data Type Description
chat_id i64 Chat identifier
message_ids Vec<i64> Vector containing IDs
Example
let chat_id: i64 = 12345;
let message_ids: Vec<i64> = vec![678910, 11121314];
api.get_message_share_url(chat_id, message_ids).await?;

// Alternatively, via the message instance:
message.share().await?;

Get Total Cost Points ๐Ÿ’ฐ

Calculate the total cost (in message points) for a specific message. Useful for metering or billing.

Parameters
Field Name Data Type Description
message_code &str Message identifier
Example
let message_code: &str = "abcdef";
api.get_total_cost_points(message_code).await?;

// Or via the message instance:
message.total_cost_points().await?;

Get List Preview Apps ๐Ÿ“ฑ

Generate a shareable URL for preview apps. Poe.com's "Previews" feature allows you to interact with web applications, such as games, animations, or data visualizations using AI coding models.

Parameters
Field Name Data Type Description
message_id i64 Message identifier
Example
let message_id: i64 = 12345;
api.get_list_preview_app(message_id).await?;

// Or via the message instance:
message.list_preview_app().await?;

Explore ๐Ÿ”Ž

Discover available users, bots, and AI models.

Parameters
pub enum EntityType {
    User,
    Bot,
}

pub struct SearchData<'a> {
    pub query: Option<&'a str>,
    pub category_name: &'a str,
    pub entity_type: EntityType,
    pub count: usize,
}
Example
use poe_api::search::Entity;
use futures_util::StreamExt;

let search_data = SearchData {
    query: Some("deepseek"),
    entity_type: EntityType::Bot,
    ..Default::default()
};

let mut result = api.explore(search_data).await?;

while let Some(entity) = result.next().await {
    match entity {
        Entity::User(user_info) => {
            // Process user data.
        }
        Entity::Bot(bot_info) => {
            // Process bot data.
        }
    }
}

Get Available Categories ๐Ÿ“‘

Retrieve a list of all available AI model categories so that you can quickly find your interest.

Example
let categories = api.get_available_categories().await?;
println!("{:?}", categories);

Expected Output:

["Official", "Reasoning", "Apps", "Search", "Image generation", "Audio and video", "For you", "Popular", "Funny", "Roleplay", "AI", "Utilities", "Programming", "Hobbies", "Learning", "Game Apps", "Featured", "Professional", "Creative writing", "Game Bots", "Advice", "Mind", "Translation", "Text analysis", "New"]

Get Bot Info ๐Ÿค–

Retrieve detailed information about a specific bot, including configuration, status, and capabilities.

Parameters
Field Name Data Type Description
bot_handle &str Bot handle name
Example
let bot_handle: &str = "Claude-3.7-Sonnet-Reasoning";
let bot_info = api.get_bot_info(bot_handle).await?;
println!("{:?}", bot_info);

Expected Output:

Some(BotInfo {
    id: "Qm90OjEwMjY=",
    bot_id: 1026,
    handle: "Claude-3.7-Sonnet-Reasoning",
    display_name: "Claude-3.7-Sonnet-Reasoning",
    model: Some("flannel_reasoning"),
    picture_url: Some("https://qph.cf2.poecdn.net/main-thumb-pb-1026-200-fvvsiofehkfrtswcutfmahqytzyfadsp.jpeg"),
    description: "Anthropic's most intelligent model (with reasoning capabilities on by default). Claude 3.7 Sonnet is a hybrid reasoning model, producing near-instant responses or extended, step-by-step thinking. Recommended for complex math or coding problems. Supports a 200k token context window.",
    powered_by: Some("Powered by Anthropic."),
    tags: ["OFFICIAL"],
    display_message_point_price: 123,
    introduction: Some(""),
    is_created_by_poe_user_account: false
})

Get User Info ๐Ÿ‘ค

Fetch profile details for a specific user.

Parameters
Field Name Data Type Description
user_handle &str User handle name
Example
let user_handle: &str = "openai";
let user_info = api.get_user_info(user_handle).await?;
println!("{:?}", user_info);

Expected Output:

Some(UserInfo {
    id: "UG9lVXNlcjoyOTEwNDAwODc5",
    uid: 2910400879,
    handle: "openai",
    full_name: "OpenAI",
    follower_count: 2470,
    medium_profile_photo_url: Some("https://qph.cf2.poecdn.net/main-thumb-2910400879-100-wrfgcbmfjrhquvwlxvypitmawpovrxoi.jpeg"),
    profile_photo_url: Some("https://qph.cf2.poecdn.net/main-thumb-2910400879-200-wrfgcbmfjrhquvwlxvypitmawpovrxoi.jpeg")
})

Follow User โž•

Add the specified user to your follow list to track updates and activities.

Parameters
Field Name Data Type Description
user_id i64 User identifier
Example
let user_id: i64 = 123456;
api.follow_user(user_id).await?;

Unfollow User โž–

Remove the specified user from your follow list.

Parameters
Field Name Data Type Description
user_id i64 User identifier
Example
let user_id: i64 = 123456;
api.unfollow_user(user_id).await?;

Set Default Message Point Limit ๐Ÿ”ข

Set the default threshold for message points per conversation. Useful for enforcing usage policies or managing message sizes.

Parameters
Field Name Data Type Description
limit usize Maximum number of message points allowed per chat
Example
let limit: usize = 420;
api.set_default_message_point_limit(limit).await?;

Set Default Bot ๐Ÿ› ๏ธ

Assign a default bot to the chat system when no specific bot is chosen.

Parameters
Field Name Data Type Description
bot_id i64 Bot identifier
Example
let bot_id: i64 = 420;
api.set_default_bot(bot_id).await?;

Set Chat Context Optimization โš™๏ธ

Toggle context optimization for a chat session to improve relevance and performance.

Parameters
Field Name Data Type Description
chat_id i64 Chat identifier
enabled bool Set true to enable or false to disable optimization
Example
let chat_id: i64 = 420;
let enabled: bool = false;
api.set_chat_context_optimization(chat_id, enabled).await?;

// Alternatively, via the message's chat instance:
message.chat().set_context_optimization(enabled).await?;

Set Chat Title ๐Ÿท๏ธ

Update the title of an existing chat conversation.

Parameters
Field Name Data Type Description
chat_id i64 Chat identifier
new_title &str New title for the chat
Example
let chat_id: i64 = 420;
let new_title: &str = "ayonima";
api.set_new_title(chat_id, new_title).await?;

// Or via the messageโ€™s chat instance:
message.chat().set_title(new_title).await?;

Purge All Conversations ๐Ÿงน

Remove all chat conversations from the system to reset the chat history.

Example
api.purge_all_conversations().await?;

Delete Chat ๐Ÿ—‘๏ธ

Delete a specific chat session using its unique identifier.

Parameters
Field Name Data Type Description
chat_id i64 Chat identifier
Example
let chat_id: i64 = 420;
api.delete_chat(chat_id).await?;

// Or via the message's chat instance:
message.chat().delete().await?;

Import Chat ๐Ÿ“ฅ

Import chat data from an external source, useful for migrating or restoring conversations.

Parameters
Field Name Data Type Description
chat_code &str Chat identifier
Example
let chat_code: &str = "sample";
api.import_chat(chat_code).await?;

Chat History ๐Ÿ“œ

Retrieve the complete history of chat conversations.

Example
while let Some(chat) = api.chat_history() {
    dbg!(chat);
}

Clear Chat Context ๐Ÿ”„

Reset the context of a specific chat conversation by clearing any stored temporary data. This is useful for restarting a conversation without any residual context.

Parameters
Field Name Data Type Description
chat_id i64 Chat identifier
Example
let chat_id: i64 = 123456;
api.clear_chat_context(chat_id).await?;

// Or via the message's chat instance:
message.chat().clear_context().await?;

Get Settings โš™๏ธ

Retrieve your settings including remaining points and additional configuration details.

Example
let my_setting = api.get_settings().await?;
println!("{:?}", my_setting);

Expected Output:

MySettings {
    uid: 659168979,
    default_bot: DefaultBot {
        display_name: "Assistant",
        bot_id: 3002,
        id: "Qm90OjMwMDI="
    },
    message_point_info: MessagePointInfo {
        message_point_reset_time: +57199-01-26T05:30:00Z,
        message_point_balance: 1827,
        total_message_point_allotment: 3000,
        all_chat_default_point_price_threshold_per_message: 500
    },
    primary_phone_number: None,
    primary_email: Some("[REDACTED]"),
    confirmed_emails: ["[REDACTED]"],
    has_active_subscription: false,
    enable_gtm_event_sending: true,
    viewer_country_code: "ID",
    global_context_optimization_status: true,
    enable_global_context_optimization: true,
    has_unread_message: false
}

License ๐Ÿ“„

MIT License

Copyright (c) 2025 zevtyardt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

A simple, lightweight, and efficient API wrapper for Poe.com.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages