Skill: happytreees/vultr-inference (version 1.1.2)

--- name: vultr-inference version: 1.0.0 description: Generate images and text using Vultr Inference API. Supports Flux image generation and various LLMs for text. Use when user wants to generate images, artwork, or text completions. author: Jimmy tags: - vultr - inference - image-generation - ai - flux - llm requires: files: - path: ~/.config/vultr/api_key description: Vultr API key (same as Vultr Cloud API key) --- # vultr-inference Generate images and text using Vultr's Inference API. ## Setup Uses the same API key as Vultr Cloud API. Store it at: ``` ~/.config/vultr/api_key ``` ## Image Generation ### Available Models | Model | Description | |-------|-------------| | `flux.1-dev` | FLUX.1-dev - High quality | | `flux.1-schnell` | FLUX.1-schnell - Fast generation | | `stable-diffusion-3.5-medium` | SD 3.5 Medium - Balanced | ### Generate Image ```bash curl -X POST "https://api.vultrinference.com/v1/images/generations" \ -H "Authorization: Bearer $VULTR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "flux.1-schnell", "prompt": "a hedgehog eating a burger in Amsterdam", "n": 1, "size": "1024x1024" }' ``` ### Parameters | Parameter | Type | Description | |-----------|------|-------------| | `model` | string | `flux.1-dev`, `flux.1-schnell`, `stable-diffusion-3.5-medium` | | `prompt` | string | Text description of image | | `n` | int | Number of images (1-4) | | `size` | string | `256x256`, `512x512`, `1024x1024` | | `response_format` | string | `url` (default) or `b64_json` | ### Response ```json { "created": 1734567890, "data": [ { "url": "https://ewr.vultrobjects.com/vultrinference-images/tmp_xxx.png" } ] } ``` ## Text Generation (Chat Completions) ### Available Models - `llama-3.1-405b-instruct` - Meta Llama 3.1 405B - `llama-3.1-70b-instruct` - Meta Llama 3.1 70B - `llama-3.1-8b-instruct` - Meta Llama 3.1 8B - `mixtral-8x7b-32768` - Mixtral 8x7B - `qwen-2-72b-instruct` - Qwen 2 72B ### Chat Completion ```bash curl -X POST "https://api.vultrinference.com/v1/chat/completions" \ -H "Authorization: Bearer $VULTR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "llama-3.1-70b-instruct", "messages": [ {"role": "user", "content": "Hello, how are you?"} ], "max_tokens": 100 }' ``` ### Parameters | Parameter | Type | Description | |-----------|------|-------------| | `model` | string | Model ID from list above | | `messages` | array | Chat messages with role and content | | `max_tokens` | int | Maximum tokens to generate | | `temperature` | float | Randomness (0-2, default 1) | | `stream` | bool | Stream response (default false) | ## Python Example ```python import os import requests [REDACTED_SECRET]"~/.config/vultr/api_key")).read().strip() # Generate image response = requests.post( "https://api.vultrinference.com/v1/images/generations", headers={"Authorization": f"Bearer {API_KEY}"}, json={ "model": "flux.1-schnell", "prompt": "a hedgehog eating a burger", "size": "512x512", "n": 1 } ) result = response.json() image_url = result["data"][0]["url"] print(f"Image URL: {image_url}") # Download image img_response = requests.get(image_url) with open("generated_image.png", "wb") as f: f.write(img_response.content) ``` ## List Available Models ```bash curl -s "https://api.vultrinference.com/v1/models" \ -H "Authorization: Bearer $VULTR_API_KEY" | jq ``` ## Troubleshooting **401 Unauthorized** - Check API key is valid - Ensure key has inference permissions **400 Bad Request** - Check model name is correct - Check size is valid (256x256, 512x512, 1024x1024) - Check prompt is not empty **Rate Limits** - Default: 60 requests per minute - Contact support for higher limits

path: scripts/vultr-inference.py
content: #!/usr/bin/env python3
"""Vultr Inference API helper for image generation."""

import argparse
import json
import os
import sys
import urllib.request

API_BASE = "https://api.vultrinference.com/v1"

def get_api_key():
    key_path = os.path.expanduser("~/.config/vultr/api_key")
    if not os.path.exists(key_path):
        print(f"Error: API key not found at {key_path}")
        sys.exit(1)
    return open(key_path).read().strip()

def generate_image(prompt, model="flux", size="1024x1024", n=1, output=None):
    """Generate an image using Vultr Inference API."""
    [REDACTED_SECRET])
    
    url = f"{API_BASE}/images/generations"
    data = {
        "model": model,
        "prompt": prompt,
        "n": n,
        "size": size
    }
    
    req = urllib.request.Request(
        url,
        data=json.dumps(data).encode(),
        headers={
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json"
        },
        method="POST"
    )
    
    print(f"Generating image with {model}...")
    with urllib.request.urlopen(req, timeout=120) as resp:
        result = json.loads(resp.read().decode())
    
    images = result.get("data", [])
    if not images:
        print("Error: No images generated")
        sys.exit(1)
    
    for i, img in enumerate(images):
        img_url = img.get("url")
        if img_url:
            if output and n == 1:
                filename = output
            else:
                filename = f"generated_{i}.png"
            
            print(f"Downloading to {filename}...")
            urllib.request.urlretrieve(img_url, filename)
            print(f"Saved: {filename}")
    
    return images

def list_models():
    """List available models."""
    [REDACTED_SECRET])
    
    url = f"{API_BASE}/models"
    req = urllib.request.Request(
        url,
        headers={"Authorization": f"Bearer {api_key}"}
    )
    
    with urllib.request.urlopen(req) as resp:
        result = json.loads(resp.read().decode())
    
    print("Available Models:")
    print("=" * 50)
    for model in result.get("data", []):
        model_id = model.get("id", "unknown")
        model_type = model.get("type", "unknown")
        print(f"  {model_id} ({model_type})")

def main():
    parser = argparse.ArgumentParser(description="Vultr Inference API")
    subparsers = parser.add_subparsers(dest="command", help="Commands")
    
    # Image generation
    img_parser = subparsers.add_parser("image", help="Generate an image")
    img_parser.add_argument("prompt", help="Image description")
    img_parser.add_argument("--model", "-m", default="flux", 
                           help="Model: flux, flux-pro, flux-dev (default: flux)")
    img_parser.add_argument("--size", "-s", default="1024x1024",
                           help="Size: 256x256, 512x512, 1024x1024 (default: 1024x1024)")
    img_parser.add_argument("--number", "-n", type=int, default=1,
                           help="Number of images (default: 1)")
    img_parser.add_argument("--output", "-o", help="Output filename")
    
    # List models
    subparsers.add_parser("models", help="List available models")
    
    args = parser.parse_args()
    
    if args.command == "image":
        generate_image(args.prompt, args.model, args.size, args.number, args.output)
    elif args.command == "models":
        list_models()
    else:
        parser.print_help()

if __name__ == "__main__":
    main()


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (HIGH)