⚡ Official Integration Guide

OpenAI Function Calling + Web Scraping

Give GPT-4 real-time web access via function calling. WebPerception API returns structured data that fits perfectly into the OpenAI tools schema.

Full Working Example

1 Define the Scraping Function
import openai, requests, json

# Define web scraping as an OpenAI function
tools = [{
    "type": "function",
    "function": {
        "name": "scrape_website",
        "description": "Scrape a website URL and extract structured content including title, main text, and links.",
        "parameters": {
            "type": "object",
            "properties": {
                "url": {
                    "type": "string",
                    "description": "The URL to scrape"
                }
            },
            "required": ["url"]
        }
    }
}]

def scrape_website(url):
    response = requests.post(
        "https://api.mantisapi.com/v1/scrape",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={
            "url": url,
            "extract": {
                "schema": {
                    "title": "string",
                    "main_content": "string",
                    "links": ["string"]
                }
            }
        }
    )
    return json.dumps(response.json())
2 Run the Agent Loop
client = openai.OpenAI()

messages = [
    {"role": "user", "content": "What are the top 3 stories on Hacker News right now?"}
]

# First call — GPT decides to use the scraping tool
response = client.chat.completions.create(
    model="gpt-4",
    messages=messages,
    tools=tools
)

# Handle tool calls
if response.choices[0].message.tool_calls:
    tool_call = response.choices[0].message.tool_calls[0]
    args = json.loads(tool_call.function.arguments)
    
    # Execute the scrape
    result = scrape_website(args["url"])
    
    # Send result back to GPT
    messages.append(response.choices[0].message)
    messages.append({
        "role": "tool",
        "tool_call_id": tool_call.id,
        "content": result
    })
    
    # Final response with web data
    final = client.chat.completions.create(
        model="gpt-4",
        messages=messages,
        tools=tools
    )
    print(final.choices[0].message.content)

Perfect Fit for OpenAI Function Calling

🔧

Native Tool Format

WebPerception returns JSON that maps directly to OpenAI's function calling response format. No transformation needed.

🧠

Schema Extraction

Define what data you want with a JSON schema. Get exactly that back. GPT-4 gets clean, structured context.

👁️

GPT-4V Compatible

Take screenshots and pass them to GPT-4V. Build agents that can visually understand any webpage.

🔗

Assistants API Ready

Works with OpenAI Assistants API. Add web scraping as a tool to any assistant.

Low Latency

Fast responses keep your agent loop snappy. No waiting for slow proxy rotations or browser pools.

💰

Free to Start

100 requests/month free. Build and test your function-calling agent before committing.

Give GPT-4 Web Access Today

Free tier. No credit card. Works with any OpenAI model that supports function calling.

Get Free API Key → Read the Docs