AICodeDog
Endpoint · Chat

Chat Completions

The chat-completion API. Request and response fields are 100% identical to OpenAI v1/chat/completions — your existing code runs by changing one baseURL line.

Endpoint

http
POST https://api.aicodedog.com/v1/chat/completions

Supported models are listed at /models. Common picks: gpt-5.4, gpt-5.4-mini, claude-opus-4-1, claude-sonnet-4-6, DeepSeek-V4-Pro, Kimi-K2.6.

Minimal request

curl
curl https://api.aicodedog.com/v1/chat/completions \ -H "Authorization: Bearer $AICODEDOG_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-5.4", "messages": [ {"role": "system", "content": "You are a concise assistant."}, {"role": "user", "content": "Explain RAG in one sentence."} ], "temperature": 0.7, "max_tokens": 500 }'

Streaming (SSE)

Add "stream": true and the response becomes Server-Sent Events — every chunk is a small incremental JSON delta:

python
from openai import OpenAI client = OpenAI(api_key="<KEY>", base_url="https://api.aicodedog.com/v1") stream = client.chat.completions.create( model="gpt-5.4", messages=[{"role": "user", "content": "Tell me a 100-word joke"}], stream=True, ) for chunk in stream: delta = chunk.choices[0].delta.content or "" print(delta, end="", flush=True)
node
const stream = await client.chat.completions.create({ model: 'gpt-5.4', messages: [{ role: 'user', content: 'Tell me a 100-word joke' }], stream: true, }); for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? ''); }

Function calling / tools

Describe the tool with a JSON Schema. The model will return tool_calls when appropriate; execute the call yourself and feed the result back as the next-turn tool message:

python
tools = [{ "type": "function", "function": { "name": "get_weather", "description": "Look up the current weather in a city", "parameters": { "type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"], }, }, }] resp = client.chat.completions.create( model="claude-sonnet-4-6", messages=[{"role": "user", "content": "Is it hot in Beijing today?"}], tools=tools, tool_choice="auto", ) tool_call = resp.choices[0].message.tool_calls[0] # tool_call.function.name == "get_weather" # tool_call.function.arguments == '{"city": "Beijing"}'

JSON mode

Forces the model to emit valid JSON. Use it for structured extraction or API integration:

json
{ "model": "gpt-5.4", "messages": [ {"role": "system", "content": "Convert user input into a {city, day} object."}, {"role": "user", "content": "What's the weather in Beijing on Tuesday?"} ], "response_format": { "type": "json_object" } }
The system prompt must mention JSON
This is an OpenAI hard requirement — if neither system nor user message contains the word "JSON", the API rejects with 400.

Multimodal (image input)

Vision-capable models (e.g. gpt-5.4, claude-opus-4-1, gemini-3-1-pro) accept mixed text + image input:

json
{ "model": "gpt-5.4", "messages": [{ "role": "user", "content": [ {"type": "text", "text": "What does the sign say?"}, { "type": "image_url", "image_url": { "url": "https://example.com/sign.jpg" } } ] }] }

Base64 dataURLs are also supported (data:image/png;base64,iVBOR...) — handy for local files.

Full parameter table

  • model (required) — model slug.
  • messages (required) — conversation history, organised by system / user / assistant / tool roles.
  • temperature — 0–2, default 1. 0 is near-deterministic, 2 is highly random.
  • top_p — nucleus-sampling threshold, default 1. Pick this OR temperature, not both.
  • max_tokens — output cap. Strongly recommended — set it to avoid runaway costs.
  • stream — streaming output, true / false.
  • stop — string or array — generation halts on encountering any of them.
  • presence_penalty / frequency_penalty — -2.0–2.0, controls topic novelty / repetition.
  • tools / tool_choice — function-calling configuration (see above).
  • response_format — JSON mode (see above).
  • seed — same seed + same input attempts to yield reproducible output (best-effort).
  • user — your end-user identifier for abuse detection.

Response format

json
{ "id": "chatcmpl-AbCdEfGhIjK", "object": "chat.completion", "created": 1747291200, "model": "gpt-5.4", "choices": [{ "index": 0, "message": { "role": "assistant", "content": "RAG = Retrieval Augmented Generation: look up first, answer second." }, "finish_reason": "stop" }], "usage": { "prompt_tokens": 24, "completion_tokens": 12, "total_tokens": 36 } }

finish_reason values: stop (natural end) / length (hit max_tokens) / tool_calls (tool triggered) / content_filter (blocked by safety policy).