Çerez kullanıyoruz. Çerezler ve tarayıcı depolaması oturumunu açık tutar ve tercihlerini hatırlar. İzin verirsen sitenin nasıl kullanıldığını da ölçeriz. İstediğin zaman . Ayrıntılar için çerez politikamıza bak.

Python

SDK rehberleri

Python

Resmi openai Python paketini base_url ve api_key ile api14'e yönlendirin; sohbet, async istemci, streaming, araçlar, Pydantic ile structured output.

api14 ile resmi openai Python paketini kullanın. base_url ve api_key değerlerini ayarlayın; model olarak herhangi bir model kimliğini (örneğin openai/gpt-5-mini) kullanın.

Kurulum

pip install openai
export API14_API_KEY="sk-api14-..."

Yapılandırma

from openai import OpenAI
import os

client = OpenAI(
    base_url="https://api14.com/api/v1",
    api_key=os.environ["API14_API_KEY"],
)

Bir async istemci de vardır: from openai import AsyncOpenAI aynı argümanları alır. Bir web sunucusunda veya toplu işte olduğu gibi aynı anda çok sayıda istek çalıştırdığınızda kullanın:

import asyncio
from openai import AsyncOpenAI

aclient = AsyncOpenAI(base_url="https://api14.com/api/v1", api_key=os.environ["API14_API_KEY"])

async def ask(q):
    r = await aclient.chat.completions.create(model="openai/gpt-5-mini", messages=[{"role": "user", "content": q}])
    return r.choices[0].message.content

async def main():
    return await asyncio.gather(*(ask(q) for q in ["What is RAG?", "What is a token?"]))

answers = asyncio.run(main())

Eşzamanlılığı planınızın dakikalık istek limitinin altında tutun. Bkz. Rehber: toplu işleme.

Argümansız OpenAI() OPENAI_BASE_URL ve OPENAI_API_KEY değerlerini okur; böylece mevcut bir uygulamayı yalnızca ortamdan api14'e yönlendirebilirsiniz:

export OPENAI_BASE_URL="https://api14.com/api/v1"
export OPENAI_API_KEY="sk-api14-..."

Sohbet

result = client.chat.completions.create(
    model="openai/gpt-5-mini",
    messages=[{"role": "user", "content": "Explain vector databases in two sentences."}],
)
print(result.choices[0].message.content)

Streaming

stream = client.chat.completions.create(
    model="anthropic/claude-sonnet-4.5",
    messages=[{"role": "user", "content": "Write a haiku about APIs."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices:
        print(chunk.choices[0].delta.content or "", end="")

Bkz. Streaming.

Tool calling

import json

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Current weather for a city",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]
messages = [{"role": "user", "content": "What's the weather in Istanbul?"}]

while True:
    res = client.chat.completions.create(model="openai/gpt-5-mini", messages=messages, tools=tools)
    msg = res.choices[0].message
    if not msg.tool_calls:
        break
    messages.append(msg)
    for call in msg.tool_calls:
        args = json.loads(call.function.arguments)
        result = get_weather(**args)  # your function
        messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)})

print(msg.content)

Bkz. Tool calling.

Structured output

client.chat.completions.parse, bir Pydantic modelini katı bir JSON Schema'ya çevirir ve ayrıştırılmış nesneyi döndürür. Güncel bir openai sürümü gerekir; eski 1.x sürümleri bunu client.beta.chat.completions.parse olarak sunar. supported_parameters alanında structured_outputs veya response_format bulunan bir model kullanın:

from pydantic import BaseModel

class Person(BaseModel):
    name: str
    born: int
    city: str

res = client.chat.completions.parse(
    model="openai/gpt-5-mini",
    messages=[{"role": "user", "content": "Extract: Ada Lovelace, born 1815 in London."}],
    response_format=Person,
)
person = res.choices[0].message.parsed  # Person(name='Ada Lovelace', born=1815, city='London')

Bkz. Structured outputs.

Görsel girdisi

import base64

image = base64.b64encode(open("photo.png", "rb").read()).decode()

res = client.chat.completions.create(
    model="google/gemini-2.5-flash",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What is in this picture?"},
            {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image}"}},
        ],
    }],
)

Herkese açık bir https:// URL'si de çalışır. Bkz. Görsel ve dosyalar.

Görseller

result = client.images.generate(
    model="openai/gpt-5.4-image-2",
    prompt="A minimalist product photo of a ceramic mug on a wooden table",
    n=1,
    extra_body={"aspect_ratio": "1:1"},
)
open("image.png", "wb").write(base64.b64decode(result.data[0].b64_json))

SDK'nın bilmediği parametreler (aspect_ratio, provider, models, reasoning) extra_body içine girer.

Konuşma ve transkripsiyon

audio = client.audio.speech.create(
    model="openai/gpt-4o-mini-tts",
    input="Hello from api14!",
    voice="alloy",
)
audio.write_to_file("speech.mp3")

text = client.audio.transcriptions.create(
    model="openai/whisper-1",
    file=open("speech.mp3", "rb"),
)
print(text.text)

Hatalar

import openai

try:
    client.chat.completions.create(
        model="openai/gpt-5-mini",
        messages=[{"role": "user", "content": "Hi"}],
    )
except openai.APIStatusError as e:
    if e.status_code == 402:
        print("Balance too low, add funds:", e.code)  # insufficient_balance
    elif e.status_code == 429:
        print("Retry after", e.response.headers.get("retry-after"), "s:", e.code)  # rate_limited
    else:
        raise

Bkz. Hatalar.

Zaman aşımları ve yeniden denemeler

SDK bağlantı hatalarını, 408, 409, 429 ve 5xx hatalarını varsayılan olarak iki kez, Retry-After değerine uyan üstel geri çekilmeyle yeniden dener. Varsayılan zaman aşımı 10 dakikadır. İkisini de istemcide veya çağrı başına with_options ile yapılandırın:

import httpx

client = OpenAI(
    base_url="https://api14.com/api/v1",
    api_key=os.environ["API14_API_KEY"],
    timeout=httpx.Timeout(60.0, connect=5.0),
    max_retries=4,
)

client.with_options(timeout=300, max_retries=0).chat.completions.create(...)

Yeniden denemek daily_limit_reached veya insufficient_balance için işe yaramaz; bunun yerine durun ve uyarı verin. Bkz. Hız limitleri.

Tüm yetenekler

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api14.com/api/v1",
  apiKey: process.env.API14_API_KEY,
});

const result = await client.chat.completions.create({
  "model": "openai/gpt-5-mini",
  "messages": [
    {
      "role": "user",
      "content": "Explain vector databases in two sentences."
    }
  ]
});
console.log(result.choices[0].message.content);