Documentation: API endpoints and usage

Overview

Base URLs Table

Base URLs API key Notes
https://localhost:1337/v1 none required use it locally
https://g4f.dev/api/groq none required Use Groq provider
https://g4f.dev/api/ollama none required Use Ollama provider
https://g4f.dev/api/pollinations.ai none required Proxy for pollinations.ai
https://g4f.dev/api/nvidia none required Use Nvidia provider
https://g4f.dev/api/grok none required Hosted Grok provider
https://g4f.dev/api/gemini none required Hosted Gemini provider
https://g4f.dev/api/gpt-oss-120b required now requires API key from g4f.dev/api_key
https://g4f.dev/api/Azure required Use Azure on my bill, get key from g4f.dev/api_key
https://g4f.dev/v1 required Hosted instance, many models, get key from g4f.dev/api_key

Also Supported API Routes:

Individual clients available for:

How to choose a base URL

API usage basics

Example payload

{
  "model": "gpt-4o",
  "temperature": 0.9,
  "messages": [{"role": "user", "content": "Hello, how are you?"}]
}

Examples

1) Python requests (local example)

import requests

payload = {
    "model": "gpt-4o",
    "temperature": 0.9,
    "messages": [{"role": "user", "content": "Hello, how are you?"}]
}

response = requests.post("http://localhost:1337/v1/chat/completions", json=payload)

if response.status_code == 200:
    print(response.text)
else:
    print(f"Request failed with status code {response.status_code}")
    print("Response:", response.text)

2) Python with OpenAI client (custom base_url)

from openai import OpenAI

client = OpenAI(
    api_key="secret",  #  A API key is required; set 'secrect' for "none required api_key" providers
    base_url="https://g4f.dev/api/gpt-oss-120b"  # replace with the chosen base_url
)

response = client.chat.completions.create(
    model="gpt-oss-120b",
    messages=[{"role": "user", "content": "Explain quantum computing"}],
)

print(response.choices[0].message.content)

3) JavaScript (HTML/JS client)

<script type="module">
    import Client from 'https://g4f.dev/dist/js/client.js';

    // Initialize a client with a base URL and optional API key
    const client = new Client({ baseUrl: 'https://g4f.dev/api/grok', apiKey: 'secret' });

    const result = await client.chat.completions.create({
        model: 'grok-4-fast-non-reasoning',
        messages: [
            { role: 'system', content: 'You are a helpful assistant.' },
            { role: 'user', content: 'Tell me a joke.' }
        ]
    });
</script>

Notes and quick tips