Files
fastgpt-python-sdk/docs/index.md
2026-01-08 17:35:21 +08:00

2.1 KiB

FastGPT Python SDK

The official Python SDK for interacting with FastGPT's OpenAPI.

Overview

FastGPT Python SDK is a client library that provides a simple, Pythonic interface to FastGPT's powerful AI platform. It supports both synchronous and asynchronous operations, with built-in retry logic, error handling, and connection pooling.

Key Features

  • Easy to Use: Simple, intuitive API design following Python best practices
  • OpenAI-Compatible: The /api/v1/chat/completions endpoint is fully OpenAI-compatible
  • Context Manager Support: Automatic resource cleanup with with statements
  • Async Support: Full async/await support for high-performance applications
  • Built-in Retry Logic: Automatic retries with configurable backoff
  • Streaming: Support for streaming responses
  • Chat Context: Maintain conversation history with chatId
  • Template Variables: Dynamic content substitution with variables

Quick Example

from fastgpt_client import ChatClient

# Basic chat completion
with ChatClient(api_key="fastgpt-xxxxx") as client:
    response = client.create_chat_completion(
        messages=[{"role": "user", "content": "Hello!"}],
        stream=False
    )
    result = response.json()
    print(result['choices'][0]['message']['content'])

Installation

pip install fastgpt-client

Client Types

Client Description
ChatClient For chat operations and conversation management
AppClient For app analytics and logs
AsyncChatClient Async version of ChatClient
AsyncAppClient Async version of AppClient

Documentation