Skip to content
FluxCDNFluxCDN
esc
On this page

DocsTools guide

FluxCDN AI in your code: SDKs and frameworks

The official OpenAI SDK in each language, with two changes: the base address and the key. The Anthropic SDKs work with the Anthropic-compatible address. The model id is anything from the models page. The examples read the key from FLUXCDN_API_KEY.

Address (OpenAI-compatible):
https://ai.fluxcdn.cloud/api/v1
Address (Anthropic-compatible):
https://ai.fluxcdn.cloud/api

Before you start

  • Create an API key. On the API keys page press “Create key” and copy the key right away. It starts with flux_live_ and is never shown in full again.
  • Give agents a key of their own and set a daily or monthly spending limit on it with “Limits”. Agents send request after request by themselves; the limit stops spending you didn't expect.
  • Have some credit in the account (Billing).
  • In the examples, put your own key where it says flux_live_YOUR_KEY.

Python (openai)

  1. Step 1: pip install openai

    The Responses API works too (client.responses.create(...)), without state: previous_response_id isn't accepted. So do client.images.generate(...), client.images.edit(...) and client.audio.speech.create(...), with the catalog's image and speaking models (API reference).

    main.py
    import os
    from openai import OpenAI
    
    client = OpenAI(
        base_url="https://ai.fluxcdn.cloud/api/v1",
        api_key=os.environ["FLUXCDN_API_KEY"],
    )
    
    reply = client.chat.completions.create(
        model="anthropic/claude-sonnet-5.5",
        messages=[{"role": "user", "content": "Hello"}],
    )
    print(reply.choices[0].message.content)

JavaScript / TypeScript (openai)

  1. Step 1: npm install openai

    Runs on Node, Deno, Bun and edge runtimes. Don't put the key in code that reaches your users' browsers; send the request from your own server.

    main.ts
    import OpenAI from "openai";
    
    const client = new OpenAI({
      baseURL: "https://ai.fluxcdn.cloud/api/v1",
      apiKey: process.env.FLUXCDN_API_KEY,
    });
    
    const reply = await client.chat.completions.create({
      model: "qwen/qwen3-coder",
      messages: [{ role: "user", content: "Hello" }],
    });
    console.log(reply.choices[0].message.content);

Anthropic SDK

  1. Step 1: The address without /v1

    The Anthropic SDKs add /v1/messages themselves, so the address is https://ai.fluxcdn.cloud/api. Any id from the catalog works, not only Claude. We accept the key in both x-api-key and Authorization: Bearer.

    pip install anthropic
    import os
    import anthropic
    
    client = anthropic.Anthropic(
        base_url="https://ai.fluxcdn.cloud/api",
        api_key=os.environ["FLUXCDN_API_KEY"],
    )
    
    message = client.messages.create(
        model="anthropic/claude-sonnet-5.5",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Hello"}],
    )
    print(message.content[0].text)

Vercel AI SDK

  1. Step 1: @ai-sdk/openai-compatible

    This package always calls Chat Completions. If you use @ai-sdk/openai, openai(...) goes to the Responses API; write openai.chat(...) for Chat Completions.

    npm install ai @ai-sdk/openai-compatible
    import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
    import { generateText } from "ai";
    
    const fluxcdn = createOpenAICompatible({
      name: "fluxcdn",
      baseURL: "https://ai.fluxcdn.cloud/api/v1",
      apiKey: process.env.FLUXCDN_API_KEY,
      includeUsage: true,
    });
    
    const { text } = await generateText({
      model: fluxcdn("anthropic/claude-sonnet-5.5"),
      prompt: "Hello",
    });

LangChain

  1. Step 1: ChatOpenAI with the FluxCDN address

    ChatOpenAI switches to the Responses API when you pass reasoning or OpenAI's built-in tools. To stay on Chat Completions, set use_responses_api=False (in JS: useResponsesApi: false).

    pip install langchain-openai
    import os
    from langchain_openai import ChatOpenAI
    
    llm = ChatOpenAI(
        model="deepseek/deepseek-v4-pro",
        base_url="https://ai.fluxcdn.cloud/api/v1",
        api_key=os.environ["FLUXCDN_API_KEY"],
    )
    print(llm.invoke("Hello").content)

LlamaIndex

  1. Step 1: OpenAILike with is_chat_model=True

    OpenAILike defaults is_chat_model to off, which calls the old /completions path we don't have. Turn both options on.

    pip install llama-index-llms-openai-like
    import os
    from llama_index.llms.openai_like import OpenAILike
    
    llm = OpenAILike(
        model="openai/gpt-5.5",
        api_base="https://ai.fluxcdn.cloud/api/v1",
        api_key=os.environ["FLUXCDN_API_KEY"],
        context_window=400000,
        is_chat_model=True,
        is_function_calling_model=True,
    )
    print(llm.complete("Hello"))

LiteLLM

  1. Step 1: openai/ before the id

    LiteLLM removes the first part of the id and sends the rest, so write openai/anthropic/claude-sonnet-5.5. A bare anthropic/ prefix sends LiteLLM to Anthropic's server.

    pip install litellm
    import os
    import litellm
    
    reply = litellm.completion(
        model="openai/anthropic/claude-sonnet-5.5",
        api_base="https://ai.fluxcdn.cloud/api/v1",
        api_key=os.environ["FLUXCDN_API_KEY"],
        messages=[{"role": "user", "content": "Hello"}],
    )
    print(reply.choices[0].message.content)

PHP (openai-php/client)

  1. Step 1: composer require openai-php/client

    PHP 8.2 or later.

    index.php
    <?php
    $client = OpenAI::factory()
        ->withApiKey(getenv('FLUXCDN_API_KEY'))
        ->withBaseUri('https://ai.fluxcdn.cloud/api/v1')
        ->make();
    
    $reply = $client->chat()->create([
        'model' => 'moonshotai/kimi-k3.1-pro',
        'messages' => [['role' => 'user', 'content' => 'Hello']],
    ]);
    echo $reply->choices[0]->message->content;

Go (openai-go)

  1. Step 1: go get github.com/openai/openai-go/v3

    main.go
    client := openai.NewClient(
        option.WithBaseURL("https://ai.fluxcdn.cloud/api/v1"),
        option.WithAPIKey(os.Getenv("FLUXCDN_API_KEY")),
    )
    reply, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{
        Model:    "anthropic/claude-sonnet-5.5",
        Messages: []openai.ChatCompletionMessageParamUnion{openai.UserMessage("Hello")},
    })
    if err == nil {
        fmt.Println(reply.Choices[0].Message.Content)
    }

.NET (OpenAI)

  1. Step 1: dotnet add package OpenAI

    Program.cs
    using OpenAI;
    using OpenAI.Chat;
    using System.ClientModel;
    
    ChatClient client = new(
        model: "anthropic/claude-sonnet-5.5",
        credential: new ApiKeyCredential(Environment.GetEnvironmentVariable("FLUXCDN_API_KEY")),
        options: new OpenAIClientOptions { Endpoint = new Uri("https://ai.fluxcdn.cloud/api/v1") });
    
    ChatCompletion reply = client.CompleteChat("Hello");
    Console.WriteLine(reply.Content[0].Text);

Java (openai-java)

  1. Step 1: com.openai:openai-java

    Main.java
    OpenAIClient client = OpenAIOkHttpClient.builder()
        .apiKey(System.getenv("FLUXCDN_API_KEY"))
        .baseUrl("https://ai.fluxcdn.cloud/api/v1")
        .build();
    
    ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
        .model("anthropic/claude-sonnet-5.5")
        .addUserMessage("Hello")
        .build();
    ChatCompletion reply = client.chat().completions().create(params);
    System.out.println(reply.choices().get(0).message().content().orElse(""));

curl

  1. Step 1: Without an SDK

    Terminal
    curl https://ai.fluxcdn.cloud/api/v1/chat/completions \
      -H "Authorization: Bearer $FLUXCDN_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "deepseek/deepseek-v4-flash",
        "messages": [{"role": "user", "content": "Hello"}]
      }'

Check it works

  1. Step 1: List the models

    With a valid key you get a list of ids back; without one, a 401.

    Terminal
    curl -s https://ai.fluxcdn.cloud/api/v1/models -H "Authorization: Bearer $FLUXCDN_API_KEY"
  2. Step 2: What each request cost

    Every answer carries x-fluxcdn-request-id, and answers that aren't streamed carry x-fluxcdn-cost-micros (the cost in millionths of a dollar). Every request is also under Activity in the console.

Troubleshooting

LlamaIndex answers 404
Set is_chat_model=True.
Error 401 or invalid_api_key
The key wasn't copied whole, was revoked, or went in the wrong field. It starts with flux_live_ and has no spaces. If the tool reads it from an environment variable, open a new terminal or window after setting it.
Error 402, insufficient_credit (in Codex: insufficient_quota) although you have credit
Before each request, the most it could cost is set aside from your credit. When the answer ends, only the real cost is taken and the rest is released. A tool that asks for a very long output on every request sets aside a large amount. Lower the tool's output limit (for example to 32000 tokens) or add credit.
Error 404 or model_not_found
The model id must be exactly as on the models page, with the maker's prefix: anthropic/claude-sonnet-5.5, not claude-sonnet-5.5. Lower case and dots matter. Copy the id rather than typing it.
A 404 that doesn't mention the model
The base address is wrong. Most tools want https://ai.fluxcdn.cloud/api/v1 and add the rest themselves; don't write /chat/completions twice and don't leave out /v1. See the which address table.
An error about previous_response_id or OpenAI's built-in tools (web search, file search, code interpreter)
Some tools switch to the Responses API without saying so. FluxCDN has it, but without memory (the whole conversation is sent each time) and without the tools that run on OpenAI's servers. Set the tool to Chat Completions: in n8n turn off Use Responses API, in Continue useResponsesApi: false, in the Vercel AI SDK openai.chat(...), in LangChain use_responses_api=False.
A CORS error or “Network error” in browser apps
FluxCDN answers requests made straight from a browser, so CORS is no longer in the way. If you still see this error, check the address and the key; a browser sometimes shows a 401 or 404 as a network error. Never put your key in a page other people open.
Error 429: rate_limit_exceeded or budget_exceeded
Either requests per minute went over the limit (wait a little; most tools retry by themselves), or this key's spending today or this month reached its limit. See it on API keys under “Limits”.
Error 502, 503, 504 or 529
The model's service was briefly unavailable. Send again; most tools do it themselves. A request that fails before answering costs nothing. If it lasts, switch to another model for a while.

Limits

  • embeddings and audio.transcriptions end in a 404. Speech is made as WAV or PCM only (mp3 and the like: a 400), and images come back as b64_json only (response_format="url": a 400) (API reference).

What doesn't work this way →