Skip to main content

Simple LLM API

A simple and easy-to-use Python wrapper for popular LLM APIs (OpenAI, Anthropic, and more).

Installation

uv is recommended for managing and installing packages in isolated environments.

uv add simple-llm-api

You can also install it using pip:

pip install simple-llm-api

Features

  • 🎯 Simple and consistent interface for multiple LLM providers
  • 🤖 Support for OpenAI, Anthropic, Google Gemini, Mistral, DeepSeek, and local LLMs
  • 🏠 Local LLM support (run locally hosted models on your own machine)
  • 🚀 Easy to use with minimal configuration
  • ⚙️ Customizable parameters for each provider
  • 🔧 **kwargs support for additional API parameters

Quick Start

OpenAI

from simple_llm_api import OpenAIAPI

openai = OpenAIAPI("YOUR_API_KEY")
response = openai.simple_request("Hi!")
print(response)

Anthropic

from simple_llm_api import AnthropicAPI

anthropic = AnthropicAPI("YOUR_API_KEY")
response = anthropic.simple_request("Hi!")
print(response)

Google Gemini

from simple_llm_api import GeminiAPI

gemini = GeminiAPI("YOUR_API_KEY")
response = gemini.simple_request("Hi!")
print(response)

Mistral

from simple_llm_api import MistralAPI

mistral = MistralAPI("YOUR_API_KEY")
response = mistral.simple_request("Hi!")
print(response)

DeepSeek

from simple_llm_api import DeepSeekAPI

deepseek = DeepSeekAPI("YOUR_API_KEY")
response = deepseek.simple_request("Hi!")
print(response)

Local LLMs

Use locally hosted models on your computer that work like OpenAI's API (like LM Studio or Ollama).

from simple_llm_api import OpenAIAPI

openai = OpenAIAPI(model="MODEL_NAME")
openai._openai_endpoint = "http://localhost:8080/v1/chat/completions"
response = openai.simple_request("Hi!")
print(response)

Advanced Usage

Each API wrapper supports various parameters for customizing the response, plus **kwargs for additional API-specific parameters:

OpenAI

openai.simple_request(
    user_prompt="Your prompt here",
    system_prompt="Custom system prompt",
    temperature=1,
    top_p=1,
    max_completion_tokens=2048
)

Anthropic

anthropic.simple_request(
    user_prompt="Your prompt here",
    system_prompt="Custom system prompt",
    temperature=1,
    max_tokens=2048
)

Gemini

gemini.simple_request(
    user_prompt="Your prompt here",
    system_prompt="Custom system prompt",
    temperature=1,
    top_k=40,
    top_p=0.95,
    max_output_tokens=2048
)

Mistral

mistral.simple_request(
    user_prompt="Your prompt here",
    system_prompt="Custom system prompt",
    temperature=0.7,
    top_p=1,
    max_tokens=2048
)

DeepSeek

deepseek.simple_request(
    user_prompt="Your prompt here",
    system_prompt="Custom system prompt",
    temperature=1,
    top_p=1,
    max_tokens=2048
)

Error Handling

The library includes custom exceptions for each API:

  • OpenAIError: OpenAIAPI Error
  • AnthropicError: AnthropicAPI Error
  • GeminiError: GeminiAPI Error
  • MistralError: MistralAPI Error
  • DeepSeekError: DeepSeekAPI Error

Disclaimer

This software is provided "as is" without any warranty. The authors are not responsible for any problems that may happen when you use this software.

This library connects to third-party LLM APIs (OpenAI, Anthropic, Google Gemini, Mistral, and DeepSeek). You must follow the rules of these APIs and manage any costs yourself.

You are responsible for how you use this software and what you do with it.

Using this software means you accept these terms.

License

This project is licensed under the MIT License.

Metadata

Release files for simple-llm-api 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-llm-api 1.3.1
File Size Uploaded
simple_llm_api-1.3.1.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple-llm-api 1.3.1
File Interpreter ABI Platform
simple_llm_api-1.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / simple_llm_api-1.3.1.tar.gz

Download URL simple_llm_api-1.3.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7c0d253a70bfc6f2ea8b207026098e50f8d2fe56a5c5ddb0443f3fdaa9a2cdfe
BLAKE2b-256 checksum
How to use checksums
b5d0bcbfaed99d413eff1824a877bb56526c885d7539de1f4d459d79da4e375e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.22

Release files / simple_llm_api-1.3.1-py3-none-any.whl

Download URL simple_llm_api-1.3.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f69a1f73821dfdc143e9b3a955f2428f1b9a57aeac13352602050db5ac1ea6d2
BLAKE2b-256 checksum
How to use checksums
e61f119648e94ee6aea6945673dadacede9e588277292297898b6490f674fb84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.22

Release history Release notifications | RSS feed

This release

1.3.1 This release

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page