Bash - uncloseai.com API Examples

This directory contains Bash examples for interacting with uncloseai.com's AI services using curl. Bash is perfect for quick scripts and command-line automation.

Prerequisites

Files in This Directory

Running with Docker

# Build the Docker image
docker build -t ai-unturf-bash languages/bash/

# Run the examples
docker run --rm ai-unturf-bash

Running Directly

# Make script executable
chmod +x examples.sh

# Run the examples
./examples.sh

Code Example: Hermes AI Chat

Using curl to call the Hermes AI endpoint for general purpose conversation:

#!/bin/bash

# Hermes AI Chat - Non-Streaming
hermes_response=$(curl -s -X POST "https://hermes.ai.unturf.com/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer dummy-key" \
  -d '{
    "model": "adamo1139/Hermes-3-Llama-3.1-8B-FP8-Dynamic",
    "messages": [{"role": "user", "content": "Give a Python Fizzbuzz solution in one line of code?"}],
    "temperature": 0.5,
    "max_tokens": 150
  }')

# Parse response with jq (optional)
echo "$hermes_response" | jq -r '.choices[0].message.content'

Code Example: Qwen 3 Coder

Qwen is specialized for coding tasks:

#!/bin/bash

# Qwen 3 Coder - Specialized for Code
qwen_response=$(curl -s -X POST "https://qwen.ai.unturf.com/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer dummy-key" \
  -d '{
    "model": "hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:Q4_K_M",
    "messages": [{"role": "user", "content": "Write a bash function to check if a port is open"}],
    "temperature": 0.5,
    "max_tokens": 200
  }')

echo "$qwen_response" | jq -r '.choices[0].message.content'

Code Example: Text-to-Speech

Generate speech from text and save to a file:

#!/bin/bash

# Text-to-Speech - Save to file
curl -s -X POST "https://speech.ai.unturf.com/v1/audio/speech" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOLO" \
  -d '{
    "model": "tts-1",
    "voice": "alloy",
    "input": "Hello from Bash! Today is a wonderful day to build something people love!"
  }' \
  --output speech.mp3

# Check if file was created
if [ -f speech.mp3 ]; then
  echo "✓ Speech file created successfully"
fi

Understanding the Code

1. Using curl for HTTP Requests

The curl command makes HTTP POST requests to the API endpoints:

2. Command Substitution

The $(command) syntax captures command output into a variable:

response=$(curl -s "https://api.example.com")
echo "$response"

3. JSON Parsing with jq

The jq tool extracts data from JSON responses:

echo "$response" | jq -r '.choices[0].message.content'
# -r flag removes quotes from string output

Common Issues

Issue: "jq: command not found"
Solution: Install jq: apk add jq (Alpine) or apt-get install jq (Debian/Ubuntu)
Issue: "curl: (60) SSL certificate problem"
Solution: Install ca-certificates: apk add ca-certificates
Issue: Empty or error response
Solution: Remove -s flag from curl to see error messages

API Endpoints

Next Steps

Try modifying the examples:

← Back to Main Page