Ointerference
DOCS
Developer Guides

Python SDK Guide

Use Interference with the official OpenAI Python library and async streams.

Python Integration Guide

Interference is a direct drop-in replacement for OpenAI in Python.


Installation

pip install openai

Synchronous Streaming Example

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.interference.dev/v1",
    api_key=os.environ.get("INTERFERENCE_API_KEY")
)

response = client.chat.completions.create(
    model="qwen3.6-plus",
    messages=[
        {"role": "system", "content": "You are a senior systems architect."},
        {"role": "user", "content": "Explain how edge computing reduces network latency."}
    ],
    stream=True
)

for chunk in response:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Asynchronous Streaming (AsyncOpenAI)

For high-concurrency web apps using FastAPI or asyncio:

import asyncio
import os
from openai import AsyncOpenAI

aclient = AsyncOpenAI(
    base_url="https://api.interference.dev/v1",
    api_key=os.environ.get("INTERFERENCE_API_KEY")
)

async def main():
    stream = await aclient.chat.completions.create(
        model="glm-5.3-flash",
        messages=[{"role": "user", "content": "Stream 5 facts about space."}],
        stream=True
    )
    async for chunk in stream:
        delta = chunk.choices[0].delta.content if chunk.choices else None
        if delta:
            print(delta, end="", flush=True)

asyncio.run(main())

Tool / Function Calling

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_stock_price",
            "description": "Fetch real-time stock ticker price",
            "parameters": {
                "type": "object",
                "properties": {
                    "symbol": {"type": "string", "description": "Ticker symbol, e.g. AAPL"}
                },
                "required": ["symbol"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="qwen3.6-plus",
    messages=[{"role": "user", "content": "What is the stock price of NVDA?"}],
    tools=tools
)

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

On this page