warp / README.md
maltose1's picture
Update README.md
2cbaff8 verified
metadata
title: Warp2API on Hugging Face
emoji: πŸš€
colorFrom: green
colorTo: blue
sdk: docker
app_port: 8000
pinned: false

Warp AI to OpenAI API Bridge

This Hugging Face Space runs a server that acts as a compatibility bridge between the Warp AI service and the standard OpenAI API.

With this bridge, you can use any OpenAI-compatible client (like custom scripts, third-party applications, etc.) to interact with Warp AI's powerful models.

How It Works

This project runs two interconnected servers:

  1. Bridge Server (Port 7861, internal): Handles Protobuf encoding/decoding and communication with Warp AI's API
  2. OpenAI Compat Server (Port 7860, public): Provides the OpenAI-compatible API interface

The workflow is:

  • Your application sends a standard OpenAI API request to the OpenAI Compat Server (port 7860)
  • The OpenAI Compat Server forwards it to the Bridge Server for Protobuf encoding
  • The Bridge Server communicates with Warp AI's service using Protobuf
  • Responses flow back through the Bridge Server (decoded to JSON) and then to your application in OpenAI format

πŸš€ Deployment on Hugging Face

Follow these steps to deploy your own instance of this bridge:

  1. Duplicate this Space: Click on the "Duplicate this Space" button at the top of this page to create your own copy. Make sure to set the visibility to private to protect your service.

  2. Set the Refresh Token Secret (Optional but Recommended): This bridge can work with or without a WARP_REFRESH_TOKEN.

    Option A: With Refresh Token (Recommended for personal use)

    • Go to your new Space's Settings.
    • Find the "Secrets management" section.
    • Click New secret and add a secret with the name WARP_REFRESH_TOKEN.
    • For the value, you'll need to obtain your refresh token from the Warp desktop client. You can typically find this by inspecting the network requests made by the application or from your .env file if you've run the project locally.
    • The application will use this token to automatically refresh the access token (JWT) needed for API calls.

    Option B: Without Refresh Token (Anonymous mode)

    • If you don't set WARP_REFRESH_TOKEN, the server will automatically acquire anonymous access tokens when needed.
    • This mode has usage quotas, but the server will automatically refresh the anonymous token when the quota is exhausted.
    • Note: Anonymous mode may have rate limits.

πŸ’» Usage

Once your Space is running, you can interact with it using the OpenAI API format. The base URL for the API will be your Space's URL (e.g., https://your-username-warp2api.hf.space).

Here is an example of how to use the chat completions endpoint with curl:

# Make sure to replace YOUR_SPACE_URL with your actual Hugging Face Space URL
# The API key can be anything, as it's not used for authentication by this bridge.
curl -X POST "https://<YOUR_SPACE_URL>/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-key" \
-d '{
    "model": "gpt-4o",
    "messages": [
        {
            "role": "user",
            "content": "Hello! Can you tell me what you are?"
        }
    ],
    "stream": false
}'

Streaming Example

To get a streaming response, simply set "stream": true:

curl -X POST "https://<YOUR_SPACE_URL>/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-key" \
-d '{
    "model": "gpt-4o",
    "messages": [
        {
            "role": "user",
            "content": "Write a short story about a robot who discovers music."
        }
    ],
    "stream": true
}'

Listing Models

You can get a list of available models by calling the /v1/models endpoint:

curl "https://<YOUR_SPACE_URL>/v1/models"

Now you have everything you need to deploy this project to Hugging Face Spaces. Just upload your project files, including the new Dockerfile and README.md, to a new Space.