API
API guides
Streaming#
stream to true and the answer arrives token by token as server-sent events, in the format of the API you called, so the SDKs' stream helpers work unchanged.OpenAI API#
import osfrom openai import OpenAIclient = OpenAI(base_url="https://fullsendai.com/v1", api_key=os.environ["FULLSEND_API_KEY"])stream = client.chat.completions.create( model="deepseek-v4.1-flash", messages=[{"role": "user", "content": "Explain this stack trace: ..."}], stream=True,)for chunk in stream: if chunk.choices: # the last chunk carries only usage print(chunk.choices[0].delta.content or "", end="", flush=True)Each data: line is a chat.completion.chunk. Text arrives in delta.content, a reasoning model's thinking in delta.reasoning_content, and tool calls as delta.tool_calls fragments to join by index (see Tool calling). The chunk with finish_reason is followed by one with usage and empty choices, then data: [DONE]. Full event example: API reference.
Anthropic API#
import osimport anthropicclient = anthropic.Anthropic(base_url="https://fullsendai.com", api_key=os.environ["FULLSEND_API_KEY"])with client.messages.stream( model="deepseek-v4.1-flash", max_tokens=1024, messages=[{"role": "user", "content": "Explain this stack trace: ..."}],) as stream: for text in stream.text_stream: print(text, end="", flush=True) final = stream.get_final_message()Events follow Anthropic's order: message_start, ping, then content_block_start / content_block_delta / content_block_stop for each text or tool_use block, message_delta with the stop reason and token counts, and message_stop. Full example: API reference.
Usage and cost#
Usage always comes at the end: in the last chunk on the OpenAI API (whether or not you set stream_options.include_usage), and in message_delta on the Anthropic API. A stream is charged once it ends, for those counts.
Stopping early#
Close the connection (break out of the loop, call stream.abort() or controller.abort()) and the model stops too. You're charged only for what was generated; when the model hadn't sent its final count yet, output is estimated from the text at about four characters a token. The call shows as Stopped in Logs.
Errors mid-stream#
Problems found before the first token (a bad key, an empty balance, a busy model) come back as a normal JSON error with its HTTP status. If the model goes quiet for 60 seconds after the stream has started, it ends with an error event (upstream_timeout on the OpenAI API, an error event on the Anthropic API). Treat what arrived as partial. See Errors.
Behind a proxy#
Cache-Control: no-cache, no-transform and X-Accel-Buffering: no, so nginx and most CDNs pass tokens straight through. If tokens still arrive all at once, turn off response buffering for that route in your proxy, and use curl -N when testing.Tool calling#
The loop#
- Send
toolswith your request. - If the answer has
finish_reason: "tool_calls", run each call inmessage.tool_calls.function.argumentsis a JSON string. - Send the conversation back with the assistant's message and one
toolmessage per call, matched bytool_call_id. - Repeat until the model answers in text.
import jsonimport osfrom openai import OpenAIclient = OpenAI(base_url="https://fullsendai.com/v1", api_key=os.environ["FULLSEND_API_KEY"])tools = [{ "type": "function", "function": { "name": "get_weather", "description": "Current weather for a city", "parameters": { "type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"], }, },}]def get_weather(city): # your code return {"city": city, "temp_c": 18, "sky": "clear"}messages = [{"role": "user", "content": "What's the weather in Paris?"}]while True: reply = client.chat.completions.create(model="deepseek-v4.1-flash", messages=messages, tools=tools) message = reply.choices[0].message messages.append(message) if not message.tool_calls: break for call in message.tool_calls: result = get_weather(**json.loads(call.function.arguments)) messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)})print(message.content){ "choices": [ { "message": { "role": "assistant", "content": null, "tool_calls": [ { "id": "call_34087531920d0de5cb6cc3d1", "type": "function", "function": { "name": "get_weather", "arguments": "{\"city\": \"Paris\"}" } } ] }, "finish_reason": "tool_calls" } ]}Tool call IDs are FullsendAI's own (call_…). Send them back exactly as you got them.
Controlling tool use#
| tool_choice | The model… |
|---|---|
"auto" | decides (the default when tools are sent) |
"required" | must call at least one tool |
"none" | answers in text |
{"type": "function", "function": {"name": "get_weather"}} | must call that tool |
parallel_tool_calls is passed to the model; models that support it can return several calls at once, so always loop over tool_calls.
Streaming tool calls#
With stream: true, calls arrive in pieces in delta.tool_calls. The first piece of each call has its index, id and function.name; later pieces add to function.arguments. Join them by index:
calls = {}for chunk in client.chat.completions.create(model="deepseek-v4.1-flash", messages=messages, tools=tools, stream=True): if not chunk.choices: continue for piece in chunk.choices[0].delta.tool_calls or []: call = calls.setdefault(piece.index, {"id": piece.id, "name": "", "arguments": ""}) call["name"] += piece.function.name or "" call["arguments"] += piece.function.arguments or ""Anthropic API#
Define tools with name, description and input_schema. The model answers with tool_use blocks and stop_reason: "tool_use"; send each result back as a tool_result block in the next user message. tool_choice takes auto, any, none or a named tool. A complete example is on the Anthropic API reference. Anthropic's server tools (web search, code execution) aren't run.
Tips#
- Tool definitions count as input tokens on every request, so keep descriptions short and the list to what the task needs.
- Give
max_tokensroom: a call cut off by the limit can arrive with incomplete or emptyarguments. - Validate arguments before running anything with side effects; the model can send values your schema doesn't allow.
- For one structured answer rather than an action, structured output is simpler than a tool.
Images#
"images": true in /v1/models) read screenshots, diagrams and photos alongside text: a UI bug, a whiteboard, an error dialog.OpenAI API#
Make the user message's content an array of parts, with an image_url part holding a public https URL or a base64 data URL.
import base64import osfrom openai import OpenAIclient = OpenAI(base_url="https://fullsendai.com/v1", api_key=os.environ["FULLSEND_API_KEY"])with open("screenshot.png", "rb") as file: image = base64.b64encode(file.read()).decode()reply = client.chat.completions.create( model="deepseek-v4.1-flash", messages=[{ "role": "user", "content": [ {"type": "text", "text": "Why is this button misaligned?"}, {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image}"}}, ], }],)print(reply.choices[0].message.content)Anthropic API#
Use an image block with a base64 or url source, as with Anthropic.
import base64import osimport anthropicclient = anthropic.Anthropic(base_url="https://fullsendai.com", api_key=os.environ["FULLSEND_API_KEY"])with open("screenshot.png", "rb") as file: image = base64.b64encode(file.read()).decode()message = client.messages.create( model="deepseek-v4.1-flash", max_tokens=1024, messages=[{ "role": "user", "content": [ {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": image}}, {"type": "text", "text": "Why is this button misaligned?"}, ], }],)Formats, size and cost#
- PNG and JPEG are the safe choices; other formats depend on the model. Send several images in one message by adding more parts.
- Images are input tokens, counted by the model, so a large screenshot costs more than a small one. The exact count is in
usage. Crop to what matters. - An image URL must be publicly reachable; for anything private, send base64.
- A model without image support refuses images with
400 invalid_request_error, or ignores them. Checkimagesin/v1/modelsfirst. - PDFs aren't read as documents. Extract the text, or send pages as images.
Reasoning#
"reasoning": true in /v1/models) let you set how hard they think.Setting the effort#
Send reasoning_effort on the OpenAI-compatible API, as with OpenAI's reasoning models. Lower effort answers sooner and uses fewer tokens; higher effort thinks longer on hard problems. The value is passed to the model as sent: low and high are the common levels. Leave it out for the model's default.
import osfrom openai import OpenAIclient = OpenAI(base_url="https://fullsendai.com/v1", api_key=os.environ["FULLSEND_API_KEY"])reply = client.chat.completions.create( model="claude-opus-5-5", # any model with "reasoning": true reasoning_effort="high", messages=[{"role": "user", "content": "Why does this recursive function overflow the stack? ..."}],)print(reply.choices[0].message.content)Reading the reasoning#
Models that share their thinking return it apart from the answer: in message.reasoning_content, or streamed in delta.reasoning_content before the delta.content tokens begin. It's null for models that don't share it. Show it, log it or ignore it; don't send it back in the next request's messages.
Cost and limits#
- Reasoning tokens are output tokens: they're in
completion_tokens(broken out incompletion_tokens_details.reasoning_tokenswhen the model reports it) and billed at the output price. - They also count toward
max_tokens. A small limit can be used up by thinking before any answer appears (finish_reason: "length"with little or no content), so give reasoning models room. - A stream can sit on reasoning tokens for a while before the first answer token. That's normal.
On the Anthropic API#
The Messages API's thinking parameter sets the effort: a budget_tokens under 4,096 thinks a little, under 16,384 a fair amount, more than that hard, and "disabled" turns thinking off. Under "adaptive" thinking, output_config.effort sets it. Models that share their reasoning return it as thinking blocks.
Structured output#
response_format on the OpenAI-compatible API is passed to the model, so you get an object you can parse rather than prose.| Option | You get |
|---|---|
{"type": "json_schema", …} | JSON shaped by your schema. The most reliable choice. |
{"type": "json_object"} | Valid JSON, shaped by your prompt. |
| A tool call | Arguments shaped by the tool's schema; works on both APIs. |
JSON Schema#
import jsonimport osfrom openai import OpenAIclient = OpenAI(base_url="https://fullsendai.com/v1", api_key=os.environ["FULLSEND_API_KEY"])reply = client.chat.completions.create( model="deepseek-v4.1-flash", messages=[{"role": "user", "content": "Extract the bug report: 'Login fails on Safari 18 with a 500 since Tuesday'"}], response_format={ "type": "json_schema", "json_schema": { "name": "bug", "strict": True, "schema": { "type": "object", "properties": { "summary": {"type": "string"}, "browser": {"type": "string"}, "status_code": {"type": "integer"}, }, "required": ["summary", "browser", "status_code"], "additionalProperties": False, }, }, },)bug = json.loads(reply.choices[0].message.content){"city": "Tokyo", "country": "Japan"}JSON mode#
"response_format": {"type": "json_object"} asks only for valid JSON. Say in the prompt which keys you want, and include the word “JSON”; some models require it.
Validate in your code#
How strictly a schema is followed depends on the model. Parse and validate before you trust the result, and check finish_reason: an answer cut off at length isn't complete JSON. With the OpenAI SDKs' helpers you get both at once:
from pydantic import BaseModelclass Bug(BaseModel): summary: str browser: str status_code: intreply = client.chat.completions.parse( model="deepseek-v4.1-flash", messages=[{"role": "user", "content": "Extract the bug report: ..."}], response_format=Bug,)bug = reply.choices[0].message.parsedOn the Anthropic API#
The Messages API has no response_format. Define one tool whose input_schema is the shape you want and set tool_choice to {"type": "tool", "name": "…"}; the tool_use block's input is your object. See Tool calling.
Stuck? Email [email protected]System status