2.1 KiB
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/completionsendpoint is fully OpenAI-compatible - Context Manager Support: Automatic resource cleanup with
withstatements - 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
- Getting Started - Installation and setup
- API Reference - Complete API documentation
- Examples - Usage examples
- Advanced Topics - Advanced features