OpenAI SDK
The ai& Inference API is wire-compatible with OpenAI’s. Use the official openai SDKs by overriding the base URL.
pip install openaifrom openai import OpenAI
client = OpenAI( base_url="https://api.aiand.com/v1", api_key="sk-your-aiand-api-key",)npm install openaiimport OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.aiand.com/v1", apiKey: "sk-your-aiand-api-key",});Chat completion
Section titled “Chat completion”response = client.chat.completions.create( model="...", messages=[{"role": "user", "content": "Hello"}],)print(response.choices[0].message.content)Streaming
Section titled “Streaming”stream = client.chat.completions.create( model="...", messages=[{"role": "user", "content": "Hello"}], stream=True, stream_options={"include_usage": True},)for chunk in stream: print(chunk.choices[0].delta.content or "", end="")