If you're looking to integrate Claude AI into your applications but are worried about compatibility with existing OpenAI tools, you're in luck. The Claude API provides a lightweight PHP wrapper that mimics the OpenAI API structure, allowing you to connect Claude AI with minimal changes to your codebase. This solution is perfect for developers who want to leverage Claude's capabilities without starting from scratch or rewriting their entire application.
What Is Claude API?
Claude API is a simple PHP script designed to connect applications and tools that are built for OpenAI with Claude AI. By mirroring the OpenAI API structure, developers can use their favorite OpenAI-compatible tools and SDKs to interact with Claude AI. This wrapper is completely unofficial and is not affiliated with Anthropic or Claude AI, which means itβs built with the community in mind, focusing on ease of use and accessibility.
Key Features
- OpenAI Drop-In Replacement: Seamlessly use standard OpenAI endpoints like
/v1/chat/completionsand/v1/modelswithout significant changes to your application. - Live Streaming: Experience real-time text streaming where responses appear as they are generated, providing a more interactive user experience.
- Easy Single-File Setup: No complex installations or dependencies required. Just upload a single PHP file and get started.
- Broad Compatibility: Works well with official OpenAI SDKs and third-party AI interfaces, making it versatile for various use cases.
- Support for Multiple Models: Choose from available models like
claude-sonnet-4-6,claude-opus-4-6, andclaude-haiku-4-5to suit your needs. - PHP 8.0+ Compatibility: Built to work with modern PHP versions, ensuring you can utilize the latest features and performance improvements.
- Minimal Configuration: Configuration is straightforward, requiring just your organization ID and session cookie to get up and running.
Installation & Setup
Setting up Claude API is a breeze. Follow these steps:
git clone https://github.com/memon-ismail/claude-api.git
cd claude-api
After cloning or downloading the repository, upload the claude.php file to your web server. Next, open claude.php in a text editor and fill in your credentials:
define('ORG_ID', 'YOUR_ORG_ID_HERE');
define('COOKIE', 'YOUR_COOKIE_HERE');
define('MODEL', 'claude-sonnet-4-6');
define('BASE_URL', 'https://claude.ai');
How to Use It
Once you have installed and configured your Claude API wrapper, using it is straightforward. Hereβs a practical example of sending a chat message and receiving a response:
<?php
require 'claude.php';
// Create a new instance of the API wrapper
$api = new ClaudeAPI();
// Send a message
$response = $api->sendMessage('Hello, Claude! How can I use you effectively?');
// Output the response
echo $response;
?>
This snippet demonstrates how to send a message to Claude and retrieve the response with minimal setup. You can easily extend this to handle user input and display responses dynamically.
Who Should Use Claude API?
Claude API is ideal for developers who are already using OpenAI tools and want to integrate Claude AI into their existing applications. It's particularly beneficial for those who appreciate a straightforward setup without the overhead of complex installations. Whether you're building chatbots, content generators, or any application that can benefit from AI, Claude API provides a hassle-free way to incorporate Claude's capabilities.
Final Thoughts
Overall, Claude API is a valuable tool for developers looking to bridge the gap between Claude AI and the existing OpenAI ecosystem. Its lightweight nature and compatibility with standard OpenAI endpoints make it an attractive option for those wanting to expand their applications with minimal effort. While it is unofficial and reliant on web session management, it opens up new possibilities for using Claude AI effectively. If you're in search of a simple yet powerful way to connect with Claude AI, give Claude API a try.