Try Chat Free Docs Pricing AI Analysis Repo Insights Free Tools About Blog
Sign in Get started free
< Back to blog
Tutorial Velona Team ·9 September 2026 ·1 min read

How to Use an AI API with Python

Python is a simple way to start

Python makes it easy to send HTTP requests to an AI API.

You only need Python, an API key and a model ID.

Install requests

pip install requests

Create the request

import requests

API_KEY = "your_api_key"

url = "https://velona.in/gateway/v1/inference/run"

payload = {
    "model": "your-model-id",
    "turns": [
        {
            "role": "user",
            "content": "Explain APIs in simple words"
        }
    ]
}

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

response = requests.post(
    url,
    headers=headers,
    json=payload
)

print(response.json())

What is happening here?

  1. Python creates a request.
  2. The API key authenticates the request.
  3. The model receives the conversation.
  4. The API returns the response.

Keep the API key outside your code

For a real application, use an environment variable.

import os

API_KEY = os.getenv("VELONA_API_KEY")

Turn it into a function

def ask_ai(question):
    response = requests.post(
        "https://velona.in/gateway/v1/inference/run",
        headers={
            "Authorization": f"Bearer {API_KEY}",
            "Content-Type": "application/json"
        },
        json={
            "model": "your-model-id",
            "turns": [
                {
                    "role": "user",
                    "content": question
                }
            ]
        }
    )

    return response.json()

print(ask_ai("Give me three Python project ideas"))

You now have a reusable Python function for your application.