Token Streaming

Open In Colab Download .ipynb

Set the OpenRouter API Key from Colab Secrets

from google.colab import userdata
OPENROUTER_API_KEY = userdata.get('OPENROUTER_API_KEY')

(Or grab the OpenRouter API key if running locally)

import os
from dotenv import load_dotenv
load_dotenv()

OPENROUTER_API_KEY = os.environ.get("OPENROUTER_API_KEY")

Create the OpenAI client with OpenRouter URL

import openai

# Initialize the OpenAI client with event hooks
client = openai.OpenAI(
    base_url='https://openrouter.ai/api/v1',
    api_key=OPENROUTER_API_KEY,
)
MODEL = 'openai/gpt-5.2-chat' #@param ["openai/gpt-5.2-chat", "anthropic/claude-sonnet-4.5", "google/gemini-2.5-pro"]

response = client.chat.completions.create(
    model=MODEL,
    messages=[
        {"role": "system", "content": "You help travelers make plans for their trips."},
        {"role": "user", "content": "Hello"},
        {"role": "assistant", "content": "Hi there!"},
        {"role": "user", "content": "What should I do on my upcoming trip to Paris?"},
    ],
    stream=True, # Enable streaming
)

# Iterate through the stream and print each token as it arrives
for chunk in response:
    # Each chunk contains a delta with the new content
    if chunk.choices[0].delta.content is not None:
        token = chunk.choices[0].delta.content
        print(token, end='', flush=True)
Paris has something for almost every type of traveler, so I’ll give you a well‑rounded starting plan. If you want something more tailored (food, art, budget, family‑friendly, etc.), just tell me.

### Must‑See Classics
- **Eiffel Tower** – Go up if it’s your first time, or enjoy views from **Trocadéro** or **Champ de Mars**.
- **Louvre Museum** – Even a 2–3 hour focused visit is worthwhile (book tickets in advance).
- **Notre‑Dame Cathedral** – Admire the exterior and nearby **Île de la Cité**; check reopening status for interior access.
- **Arc de Triomphe** – Climb to the top for one of the best city views.

### Neighborhoods to Explore
- **Montmartre** – Artistic vibes, Sacré‑Cœur, charming streets.
- **Le Marais** – Trendy shops, historic mansions, great food.
- **Latin Quarter** – Lively, student energy, bookshops, cafés.
- **Saint‑Germain‑des‑Prés** – Classic cafés and upscale shopping.

### Food & Drink Experiences
- Eat at a **local bistro** (look for a fixed‑price *menu du jour*).
- Try **croissants & pain au chocolat** from a neighborhood bakery.
- Visit a **fromagerie** and **wine bar**.
- Enjoy café culture: sit outside, order a coffee or wine, and people‑watch.
- Don’t miss **crêpes**, **macarons**, and **cheese**.

### Cultural & Unique Experiences
- **Seine River cruise** (especially at night).
- **Musée d’Orsay** for Impressionist art.
- **Versailles** day trip for palace and gardens.
- **Cooking class** or **food tour**.
- Wander without a plan—Paris is best discovered on foot.

### Practical Tips
- Buy museum tickets in advance to skip lines.
- Learn a few French phrases—it goes a long way.
- Dress comfortably but stylishly; Parisians walk a lot.
- Use public transport (metro is fast and affordable).

If you’d like, tell me:
- How many days you’ll be there  
- Time of year  
- Your interests (food, museums, nightlife, romance, budget travel)

I can build you a **day‑by‑day itinerary** just for your trip.