Skip to content

OpenAI-format API ​

Flash API exposes a fully OpenAI-compatible API. It supports every GPT model, plus other models that speak the OpenAI format.

Endpoint ​

https://ai.flashapi.top/v1

Authentication ​

Add your API key to the request header:

http
Authorization: Bearer YOUR_API_KEY

Chat Completions ​

Overview ​

The core text endpoint for single-turn and multi-turn conversations.

Endpoint ​

POST /v1/chat/completions

Important ​

GPT, Claude, Gemini and other text models all support both streaming and non-streaming output. Use "stream": false for short requests or one-shot structured results. For long answers and interactive UIs, use "stream": true so content shows up sooner.

Request examples ​

GPT model (non-streaming) ​

bash
curl https://ai.flashapi.top/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-6.1-sol",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful AI assistant"
      },
      {
        "role": "user",
        "content": "Write a quicksort in Python"
      }
    ],
    "stream": false,
    "temperature": 0.7,
    "max_tokens": 2000
  }'

Claude model (non-streaming) ​

bash
curl https://ai.flashapi.top/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "claude-opus-5-5",
    "messages": [
      {
        "role": "user",
        "content": "Hello!"
      }
    ],
    "stream": false,
    "temperature": 0.7
  }'

Request parameters ​

ParameterTypeRequiredDescription
modelstringYesModel name, e.g. gpt-6.1-sol
messagesarrayYesList of conversation messages
streambooleanNotrue returns an SSE stream, false returns the full JSON. Supported by all text models
temperaturenumberNoSampling temperature, 0–2. Defaults to 1
max_tokensintegerNoMaximum number of tokens to generate
top_pnumberNoNucleus sampling, 0–1
stopstring/arrayNoStop sequences
stream_optionsobjectNoStreaming options

Messages format ​

json
{
  "messages": [
    {
      "role": "system",
      "content": "System prompt"
    },
    {
      "role": "user",
      "content": "User message"
    },
    {
      "role": "assistant",
      "content": "Assistant reply"
    }
  ]
}

Roles:

  • system: the system prompt that sets the model's behavior
  • user: the user's message
  • assistant: the model's reply (for multi-turn conversations)

Response format ​

json
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-6.1-sol",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "This is the model's reply"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 56,
    "completion_tokens": 31,
    "total_tokens": 87
  }
}

Streaming ​

Every text model can stream. Set stream to true and the server keeps sending SSE events.

GPT model streaming request (optional) ​

bash
curl https://ai.flashapi.top/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-6.1-sol",
    "messages": [{"role": "user", "content": "Hi"}],
    "stream": true,
    "stream_options": {
      "include_usage": true
    }
  }'

Streaming response format (SSE) ​

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-6.1-sol","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-6.1-sol","choices":[{"index":0,"delta":{"content":"Hi"},"finish_reason":null}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-6.1-sol","choices":[{"index":0,"delta":{"content":" there"},"finish_reason":null}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-6.1-sol","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":9,"completion_tokens":2,"total_tokens":11}}

data: [DONE]

Claude model non-streaming request ​

bash
curl https://ai.flashapi.top/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "claude-opus-5-5",
    "messages": [{"role": "user", "content": "Hi"}],
    "stream": false
  }'

Supported models ​

GPT family ​

ModelDescriptionContextOutput
gpt-6.1-solCurrent recommended model1MStreaming or non-streaming

Check GET /v1/models with your group's key and the console for available models.

Claude family (OpenAI format, streaming optional) ​

ModelDescriptionContextStreaming
claude-opus-5-5Current recommended Claude1MOptional

Gemini family (OpenAI format, streaming optional) ​

ModelDescriptionContextStreaming
gemini-3.1-pro-previewRecommended Gemini Pro model1MOptional
gemini-3.8-flashRecommended Gemini Flash model1MOptional

Code examples ​

Python (GPT model, streaming) ​

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://ai.flashapi.top/v1"
)

# Stream long answers
stream = client.chat.completions.create(
    model="gpt-6.1-sol",
    messages=[
        {"role": "system", "content": "You are a coding assistant"},
        {"role": "user", "content": "Write a Python function that computes the Fibonacci sequence"}
    ],
    stream=True,
    stream_options={"include_usage": True}
)

for chunk in stream:
    if chunk.choices:
        content = chunk.choices[0].delta.content
        if content is not None:
            print(content, end="")
    
    # Usage stats (in the last chunk)
    if hasattr(chunk, 'usage') and chunk.usage:
        print(f"\n\nUsed {chunk.usage.total_tokens} tokens")

Python (non-streaming, works with every text model) ​

python
# GPT, Claude and Gemini all support non-streaming requests
response = client.chat.completions.create(
    model="claude-opus-5-5",
    messages=[
        {"role": "user", "content": "Write a quicksort algorithm"}
    ],
    stream=False
)

print(response.choices[0].message.content)

Node.js (GPT model, streaming) ​

javascript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://ai.flashapi.top/v1'
});

async function main() {
  // Stream long answers
  const stream = await client.chat.completions.create({
    model: 'gpt-6.1-sol',
    messages: [
      { role: 'system', content: 'You are a coding assistant' },
      { role: 'user', content: 'Write a quicksort algorithm' }
    ],
    stream: true,
    stream_options: { include_usage: true }
  });

  for await (const chunk of stream) {
    if (chunk.choices[0]?.delta?.content) {
      process.stdout.write(chunk.choices[0].delta.content);
    }
    
    // Usage stats
    if (chunk.usage) {
      console.log(`\n\nUsed ${chunk.usage.total_tokens} tokens`);
    }
  }
}

main();

Node.js (non-streaming) ​

javascript
// Every text model can be called without streaming
async function callClaude() {
  const completion = await client.chat.completions.create({
    model: 'claude-opus-5-5',
    messages: [
      { role: 'user', content: 'Write a quicksort algorithm' }
    ],
    stream: false
  });

  console.log(completion.choices[0].message.content);
}

cURL (GPT model) ​

bash
# GPT models can stream too
curl https://ai.flashapi.top/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-6.1-sol",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ],
    "stream": true,
    "stream_options": {
      "include_usage": true
    }
  }'

cURL (Claude, non-streaming) ​

bash
# Claude model, non-streaming
curl https://ai.flashapi.top/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "claude-opus-5-5",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ],
    "stream": false
  }'

Error handling ​

Error response format ​

json
{
  "error": {
    "message": "Error description",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}

Common error codes ​

StatusError typeDescription
401invalid_api_keyInvalid API key
429rate_limit_exceededRate limit exceeded
500server_errorServer error
503service_unavailableService unavailable

Error handling example ​

python
from openai import OpenAI, APIConnectionError, APIStatusError, APIError

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://ai.flashapi.top/v1"
)

try:
    # Stream so output shows up as it's generated
    stream = client.chat.completions.create(
        model="gpt-6.1-sol",
        messages=[{"role": "user", "content": "Hello"}],
        stream=True
    )
    
    for chunk in stream:
        if chunk.choices:
            content = chunk.choices[0].delta.content
            if content:
                print(content, end="")
            
except APIConnectionError as e:
    print(f"Connection failed: {e}")
except APIStatusError as e:
    print(f"HTTP status: {e.status_code}")
    print(f"Error response: {e.body}")
except APIError as e:
    print(f"API error: {e}")

Best practices ​

1. Set a sensible timeout ​

python
client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://ai.flashapi.top/v1",
    timeout=30.0  # 30-second timeout
)

2. Add retries ​

python
from tenacity import retry, stop_after_attempt, wait_exponential

@retry(
    stop=stop_after_attempt(3),
    wait=wait_exponential(multiplier=1, min=4, max=10)
)
def call_api():
    return client.chat.completions.create(...)

3. Stream when it makes sense ​

Every text model supports both streaming and non-streaming. Stream long answers; use non-streaming for short requests and structured results:

python
# GPT model, streaming
stream = client.chat.completions.create(
    model="gpt-6.1-sol",
    messages=[{"role": "user", "content": "Write an article"}],
    stream=True,
    stream_options={"include_usage": True}
)

for chunk in stream:
    if chunk.choices:
        content = chunk.choices[0].delta.content
        if content:
            print(content, end='')

# Claude model, non-streaming
response = client.chat.completions.create(
    model="claude-opus-5-5",
    messages=[{"role": "user", "content": "Write an article"}],
    stream=False
)
print(response.choices[0].message.content)

4. Keep token usage in check ​

python
response = client.chat.completions.create(
    model="gpt-6.1-sol",
    messages=[...],
    max_tokens=500,  # Cap output length
    temperature=0.3  # Less randomness
)

# Check token usage
print(f"Used {response.usage.total_tokens} tokens")

Next steps ​

One base URL for GPT, Claude and Gemini