LONG AI
Home › Blog › One API Key, Every Model: How to Integra

One API Key, Every Model: How to Integrate a Multi-Model Marketplace

Category:教程 · 6 min read · 2026-11-16

Integrating one API key to call hundreds of AI models

The short answer

To call every model on this platform, you only need to change one thing: point your base URL from the vendor's endpoint to https://ai.dijinlong.com/v1 and swap in a platform key from the console. From there, which model you call is decided entirely by the model field — gpt-6-luna today, kling-3.0 for video tomorrow, and all it takes is editing one string. No second key required. Every endpoint and error code below was verified live on November 16, 2026, and the samples are copy-paste ready.

Which request formats are supported

The gateway adapts protocols at the edge, so the two dominant request formats work out of the box — your existing code likely needs no changes at all:

FormatEndpointUse case
OpenAI format/v1/chat/completionsText chat; the default for most frameworks
Anthropic format/v1/messagesClaude-family models or Anthropic SDK projects
Model list/v1/modelsSee which models your key can call

Authentication accepts three header styles: Authorization: Bearer sk-xxx, x-api-key: sk-xxx, and x-goog-api-key: sk-xxx. OpenAI SDKs use the first, Anthropic SDKs the second, Google SDKs the third — keep your SDK's auth code, just swap the URL and the key.

Error responses keep the vendor's shape, too: the OpenAI-style endpoint returns API_KEY_REQUIRED / INVALID_API_KEY with authentication_error, while the Anthropic-style endpoint returns the Anthropic {"type":"error"} structure. Your existing error handling carries over unchanged.

Three steps, copy-paste code

Step 1 — get a key. After registering, create an API key in the console; it looks like sk-xxx. The full key is shown exactly once at creation, so save it immediately.

Step 2 — point the base URL at the platform. A complete Python example with the OpenAI SDK:

from openai import OpenAI

client = OpenAI(
    api_key="sk-your-platform-key",
    base_url="https://ai.dijinlong.com/v1",
)

resp = client.chat.completions.create(
    model="gpt-6-luna",
    messages=[{"role": "user", "content": "Introduce yourself in one sentence"}],
)
print(resp.choices[0].message.content)

On the Anthropic SDK, change two lines: set base_url to https://ai.dijinlong.com (no /v1 here — the SDK appends it) and use your platform key.

Step 3 — send a probe request. Call /v1/models to list what your key can reach; it confirms the key works and your model names are spelled correctly:

curl https://ai.dijinlong.com/v1/models \
  -H "Authorization: Bearer sk-your-platform-key"

That's it. These three steps are universal — text, image, and video models all share the same key and the same endpoint.

Switching models: one string

Once connected, switching models means changing the model value. As of November 16, 2026, the platform carries 138 on-sale models: 94 text, 30 image, and 14 video, from 51 vendors (391 models in the full catalog). Each model's exact name, billing unit, and tier prices live in model docs — check them before calling, because a versioned name and the bare name are two different models (a -fast suffix means a cheaper, quicker variant). A misspelled name fails immediately with "model not found".

Response shapes differ by category: text models return choices, while image and video models bill per image or per second and return generated results or task IDs. When one project mixes categories, make model names a config value rather than a hardcoded string — that keeps price-versus-capability tradeoffs a one-line change.

What one key unlocks, by category Data as of 2026-11-16 · 138 on-sale models from 51 vendors 94 Text 30 Image 14 Video

How pricing works: effective price, 50% ceiling

The platform prices every model as list price × seller discount: multiple sellers compete on each model, no quote may exceed 50% of list, and you pay the effective price at settlement time. The price table shows list price plus the deepest current discount, so the real cost is visible at a glance.

Three wallet-relevant notes. First, input and output are billed separately, with output typically four to five times input — estimate both. Second, cache-hit pricing is far below normal input pricing; long requests with repeated prefixes (agents with fixed system prompts, for instance) save a lot by enabling caching. Third, failed requests are not charged — fees settle on successful calls only, so retries carry no financial risk.

Common pitfalls and how to debug them

API_KEY_REQUIRED: the request carried no key at all. Check the auth header — there's a space between Bearer and the key; and if you route through a proxy or gateway, confirm it isn't stripping the header.

INVALID_API_KEY: the key is invalid or deleted. Check its status in the console and regenerate if needed. A missing sk- prefix or a copied trailing space also triggers this.

"Model not found": a misspelled name, or the model currently has no sellers. Verify names against /v1/models, then check live supply on the model plaza — every model there shows real-time quotes and seller counts, and out-of-stock models are flagged.

429 (rate limited): retry with exponential backoff (1s, 2s, 4s) and set timeouts on critical requests. Never retry bare in a hot loop — it only deepens the throttle.

Three tips for new integrations

First, start small: wire up the pipeline (probe, chat, settlement) on the cheapest tier before switching to your production model, so debugging doesn't burn budget. Second, keep model names in config: prices and capabilities shift weekly, and config makes switching a one-liner. Third, watch effective price, not list price: discounts vary a lot across sellers for the same model, so confirm the deepest tier on the price table before you commit — and for sustained high volume, compare tiers across sellers deliberately.

相关文章

GPT-6.2 Cuts Prices 20%: What the AI Price War Means

GPT-6.2 cuts list prices 20%, yet platform discounts run deeper: gpt-6-astra trades at under 1% of list. What this week's AI price war means for buyer

What Is Prompt Caching? How Cache Tokens Cut API Bills

Prompt caching stores a repeated prompt prefix and bills cache reads at 5-12% of normal input. Real prices, hit conditions, and how to cut your API bi

All 12 Claude Models Compared: Price and Best Use

Twelve Claude versions are on sale. The newest opus-5-5 costs $8.91 a month; the oldest opus-4-6 costs $49.50. Full table and a pick for each workload

Which AI Model Writes Code Best? Speed and Price Tested

gpt-5.6-terra and deepseek-v4.1-flash win on price and reliability; gemini-3.8-flash is fastest. Effective prices, measured speed, and a three-tier pi

Kling vs Hailuo vs Seedance: Which Chinese Video Model Wins on Price?

Hailuo 2.3-fast has the lowest effective price (about $0.00185/s), Kling 3.0 offers the fullest range up to 4K, and Seedance 2.5 costs most but render