DEV Community

APIKO AI API
APIKO AI API

Posted on

Use one OpenAI-compatible API in LangChain and LlamaIndex

LangChain and LlamaIndex both ship first-class OpenAI integrations. Because APIKO AI API speaks the OpenAI API, you can reuse those integrations to reach models from OpenAI, Anthropic, Google, DeepSeek and more: point them at https://api.apiko.app/v1, pass an APIKO key, and pick a model id.

Setup

Create an API key at apiko.app (pay as you go in USD, credit packs from $5, no subscription), then:

export APIKO_API_KEY=sk-...
Enter fullscreen mode Exit fullscreen mode

Model ids come from the model marketplace, which shows live prices and availability for every model.

LangChain

# pip install langchain-openai
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="claude-sonnet-5-5",
    base_url="https://api.apiko.app/v1",
    api_key=os.environ["APIKO_API_KEY"],
)

print(llm.invoke("Give me three names for a weather app.").content)
Enter fullscreen mode Exit fullscreen mode

Swapping providers is a one-word change, so you can run the same chain against several models:

for model in ["gpt-6-astra", "claude-sonnet-5-5", "gemini-3.5-flash", "deepseek-v4-flash"]:
    llm = ChatOpenAI(model=model, base_url="https://api.apiko.app/v1", api_key=os.environ["APIKO_API_KEY"])
    print(model, "->", llm.invoke("Summarize what an API gateway does in one line.").content)
Enter fullscreen mode Exit fullscreen mode

LlamaIndex

# pip install llama-index-llms-openai-like
import os
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="gemini-3.5-flash",
    api_base="https://api.apiko.app/v1",
    api_key=os.environ["APIKO_API_KEY"],
    is_chat_model=True,
)

print(llm.complete("Explain retrieval-augmented generation in two sentences."))
Enter fullscreen mode Exit fullscreen mode

Why route through one endpoint

  • One key and one balance for every provider instead of separate accounts.
  • Automatic routing and failover when an upstream provider has trouble.
  • Failed calls cost nothing: when an upstream call fails, the amount held for it goes back to your balance automatically.

More examples are in this gist and the docs at apiko.app/docs.

Top comments (0)