OpenAI SDK
Get web search results from Flux using the OpenAI SDK.
On this page
Your app already calls the OpenAI API, but the model cannot see today's web or tell your users where an answer came from. Point the SDK at Flux and the same call returns current passages, each with its source.
Set up
Install the SDK
pip install openainpm install openaiPoint the client at Flux
Use your Flux key and the Flux base URL. Everything else stays the same.
client.pyimport osfrom openai import OpenAIclient = OpenAI( base_url="https://fluxsearch.io/api/v1", api_key=os.environ["FLUX_API_KEY"],)import OpenAI from "openai";const client = new OpenAI({ baseURL: "https://fluxsearch.io/api/v1", apiKey: process.env.FLUX_API_KEY,});
Search
Ask about something current
Use flux-search-1. The reply is the passages Flux read, joined as prose.
completion = client.chat.completions.create( model="flux-search-1", messages=[{"role": "user", "content": "Which city will host Eurovision 2027?"}],)print(completion.choices[0].message.content)const completion = await client.chat.completions.create({ model: "flux-search-1", messages: [{ role: "user", content: "Which city will host Eurovision 2027?" }],});console.log(completion.choices[0]?.message.content);It will consist of two semi-finals on 11 and 13 May and a final on 15 May 2027, held at Arena Burgas in Burgas, Bulgaria. [when: May 11, 2027, May 15, 2027]It is being organised by the European Broadcasting Union (EBU) and host broadcaster Bulgarian National Television (BNT), which will stage the event after winning the 2026 contest for Bulgaria with th…By 21 May, the Bulgarian government had begun establishing an interdepartmental working group, headed by Deputy Prime Minister Ivo Hristov, to coordinate preparations for the contest.[10][11][12] BNT…Eurovision Song Contest 2027: Burgas.We will update this page with all the information about Burgas 2027 as it appears···Date: When is Eurovision 2027?The Eurovision week will have three shows: Semi-final 1 on Tuesday, Semi-final 2 on T…Take a stroll through the Sea Garden, the city’s famous waterfront park, or enjoy the cafés and restaurants along the seafront.Discover Burgas’ maritime charm: As Bulgaria’s fourth-largest city and o……Show where the answer came from
url_citation is a page a passage came from. provenance lists what the passage mentions, each with a type: a person, organisation, place, event or time. Times arrive as real dates in canonical. When the text is a word like "its", canonical holds the name it stands for.
LABELS = { "person": "People", "organisation": "Organisations", "place": "Places", "time": "Dates",}sources, found = {}, {label: [] for label in LABELS.values()}message = completion.choices[0].message.to_dict()for annotation in message.get("annotations", []): if annotation["type"] == "url_citation": sources[annotation["url"]] = annotation["title"] continue for entity in annotation["entities"]: if entity["type"] == "time": name = entity["canonical"] else: # A name with a canonical form was written as a word like "its": skip it. name = None if entity["canonical"] else entity["text"] names = found.get(LABELS.get(entity["type"])) if name and names is not None and name not in names: names.append(name)for url, title in sources.items(): print("Source:", title, url)for label, names in found.items(): print(f"{label}: {'; '.join(names)}")type Entity = { type: string; text: string; canonical: string | null };type FluxAnnotation = | { type: "url_citation"; url: string; title: string } | { type: "provenance"; entities: Entity[] };const LABELS: Record<string, string> = { person: "People", organisation: "Organisations", place: "Places", time: "Dates",};const sources = new Map<string, string>();const found = new Map(Object.values(LABELS).map((label) => [label, [] as string[]]));const annotations = (completion.choices[0]?.message.annotations ?? []) as unknown as FluxAnnotation[];for (const annotation of annotations) { if (annotation.type === "url_citation") { sources.set(annotation.url, annotation.title); continue; } for (const entity of annotation.entities) { // A name with a canonical form was written as a word like "its": skip it. const name = entity.type === "time" ? entity.canonical : entity.canonical ? null : entity.text; const names = found.get(LABELS[entity.type] ?? ""); if (name && names && !names.includes(name)) names.push(name); }}for (const [url, title] of sources) console.log("Source:", title, url);for (const [label, names] of found) console.log(`${label}: ${names.join("; ")}`);Source: Eurovision Song Contest 2027 https://en.wikipedia.org/wiki/Eurovision_Song_Contest_2027Source: Host City Reveal - Eurovision Song Contest 2027 https://www.youtube.com/watch?v=dNWhlLBY5R4Source: Eurovision 2027 on the beach? Well if Burgas is named host ... https://www.facebook.com/wiwibloggs/videos/%EF%B8%8F-eurovision-2027-on-the-beach-well-if-burgas-is-named-host-city-you-may-be-e…Source: Eurovision Song Contest 2027 to be held in Burgas, Bulgaria https://www.bbc.com/news/articles/cly8p8lpyvmoSource: Burgas is Eurovision 2027 Host City! 🇧🇬 REACTION https://www.youtube.com/watch?v=OljJ6bSeWuAPeople: Dara; Deputy Prime Minister Ivo HristovOrganisations: European Broadcasting Union (EBU); BNT),; the Bulgarian government; BNT; EBU; the EBUPlaces: Arena Burgas; Burgas; Bulgaria; Sofia; the Black SeaDates: May 11, 2027; May 15, 2027; 2026; May 21, 2026; Jun 8, 2026; Jul 3, 2026; Jul 13, 2026; Aug 13, 2026; 2027Only search sites you trust
Add a web_search tool with allowed_domains. Frameworks that already send one work with no changes.
completion = client.chat.completions.create( model="flux-search-1", messages=[{"role": "user", "content": "WWDC keynote highlights"}], tools=[{"type": "web_search", "filters": {"allowed_domains": ["apple.com"]}}],)Lineage
Read a page for your model
Use flux-lineage-1 and send url. Flux fetches the page and returns its key passages, with names and dates filled in. No search runs.
page = client.chat.completions.create( model="flux-lineage-1", messages=[{"role": "user", "content": "Read this page."}], extra_body={"url": "https://www.macrumors.com/roundup/wwdc/"},)print(page.choices[0].message.content)const page = await client.chat.completions.create({ model: "flux-lineage-1", messages: [{ role: "user", content: "Read this page." }], // @ts-expect-error url is a Flux field url: "https://www.macrumors.com/roundup/wwdc/",});console.log(page.choices[0]?.message.content);WWDC 2026: Everything to ExpectShow RoundupsShow Forums menuVisit Forums.Apple's 37th annual Worldwide Developers Conference took place from June 8 to June 12, 2026.It began a keynote event the morning of Monday, June 8.Like WWDC 2025, WWDC 2026 was be a hybrid event. [what: It -> The Worldwide Developers Conference]Apple held WWDC primarily online, allowing developers around the world to attend sessions and meet with Apple engineers at no cost.Apple invited select developers, students, and members of the media to the Apple Park campus in Cupertino, California.Attendees were able the keynote event at the Steve Jobs theater, attend the Platform State of the Union address and participate in-person labs and sessions with Apple engineers.The Worldwide Develope……Annotation
- type (required)string
url_citationprovenance- start_index (required)integer
- end_index (required)integer
- urlstring
url_citationonly. The page the passage came from.- titlestring
url_citationonly. The title of that page.- source_startinteger | null
provenanceonly. Where the passage starts in the document you sent. Null for search results.- source_endinteger | null
- scorenumber | null
- entitiesCompatEntity[]