### Python: Tool Use Example Source: https://github.com/nahcrof-code/crofai/blob/main/README.md Demonstrates how to enable tool use for LLM inference. This example defines a function `get_horoscope` and shows how the model can call it. Replace 'MODEL-FROM-LIST' with a valid model ID. ```python from openai import OpenAI import json client = OpenAI( base_url="https://crof.ai/v1", api_key="api-key-here" ) tools = [{ # tootally original example "type": "function", "function": { "name": "get_horoscope", "description": "Get today's horoscope for an astrological sign.", "parameters": { "type": "object", "properties": { "sign": { "type": "string", "description": "An astrological sign like Taurus or Aquarius", }, }, "required": ["sign"], "additionalProperties": False, }, "strict": True, }, }] def get_horoscope(sign): return f"{sign}: Next Tuesday you will befriend a baby otter." messages = [ {"role": "user", "content": "What is my horoscope? I am an Aquarius."} ] stream = client.chat.completions.create( model="MODEL-FROM-LIST", messages=messages, tools=tools, stream=True ) for chunk in stream: delta = chunk.choices[0].delta if delta.content: print(delta.content, end="", flush=True) if delta.tool_calls: for tc in delta.tool_calls: print(f"\nTool call: {tc.function.name}") if tc.function.arguments: print(f"Args: {tc.function.arguments}") ``` -------------------------------- ### Python (vision models) Source: https://github.com/nahcrof-code/crofai/blob/main/README.md This example demonstrates how to use vision models to process images by providing an image URL in the message content. ```APIDOC ## Python (vision models) ### Description This example demonstrates how to use vision models to process images by providing an image URL in the message content. ### Code ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="api-key-here" ) response = client.chat.completions.create( model="kimi-k2.5", # vision models are labeled in the pricing page with the (vision) tag messages=[ { "role": "user", "content": [ {"type": "text", "text": "What is in this image?"}, { "type": "image_url", "image_url": { "url": "https://files.nahcrof.com/file/crofai-black.png", }, }, ], } ], stream=True ) for chunk in response: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() ``` ``` -------------------------------- ### Python (reasoning model example) Source: https://github.com/nahcrof-code/crofai/blob/main/README.md Demonstrates how to access and print reasoning content from a streaming response, useful for models that provide step-by-step thought processes. ```APIDOC ## Python (reasoning model example) ### Description Demonstrates how to access and print reasoning content from a streaming response, useful for models that provide step-by-step thought processes. ### Code ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="api-key-here" ) response = client.chat.completions.create( model="MODEL-FROM-LIST", messages=[ {"role": "user", "content": "Howdy there! How are you?"} ], stream=True # Enable streaming ) for chunk in response: try: if chunk.choices and chunk.choices[0].delta.reasoning_content: print(chunk.choices[0].delta.reasoning_content, end="", flush=True) except AttributeError: pass if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() ``` ``` -------------------------------- ### Python (tool use) Source: https://github.com/nahcrof-code/crofai/blob/main/README.md Example of how to configure and use tools with the LLM for function calling, including handling tool calls and arguments in the response. ```APIDOC ## Python (tool use) ### Description Example of how to configure and use tools with the LLM for function calling, including handling tool calls and arguments in the response. ### Code ```python from openai import OpenAI import json client = OpenAI( base_url="https://crof.ai/v1", api_key="api-key-here" ) tools = [{ "type": "function", "function": { "name": "get_horoscope", "description": "Get today's horoscope for an astrological sign.", "parameters": { "type": "object", "properties": { "sign": { "type": "string", "description": "An astrological sign like Taurus or Aquarius", }, }, "required": ["sign"], "additionalProperties": False, }, "strict": True, }, }] def get_horoscope(sign): return f"{sign}: Next Tuesday you will befriend a baby otter." messages = [ {"role": "user", "content": "What is my horoscope? I am an Aquarius."} ] stream = client.chat.completions.create( model="MODEL-FROM-LIST", messages=messages, tools=tools, stream=True ) for chunk in stream: delta = chunk.choices[0].delta if delta.content: print(delta.content, end="", flush=True) if delta.tool_calls: for tc in delta.tool_calls: print(f"\nTool call: {tc.function.name}") if tc.function.arguments: print(f"Args: {tc.function.arguments}") ``` ``` -------------------------------- ### Python (with Streaming) Source: https://github.com/nahcrof-code/crofai/blob/main/README.md This example shows how to enable and handle streaming responses from the LLM inference API. ```APIDOC ## Python (with Streaming) ### Description This example shows how to enable and handle streaming responses from the LLM inference API. ### Code ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="api-key-here" ) response = client.chat.completions.create( model="MODEL-FROM-LIST", messages=[ {"role": "user", "content": "Howdy there! How are you?"} ], stream=True # Enable streaming ) for chunk in response: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() ``` ``` -------------------------------- ### Python (no Streaming) Source: https://github.com/nahcrof-code/crofai/blob/main/README.md This example demonstrates how to perform a basic LLM inference request without streaming the response using the OpenAI Python SDK. ```APIDOC ## Python (no Streaming) ### Description This example demonstrates how to perform a basic LLM inference request without streaming the response using the OpenAI Python SDK. ### Code ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="api-key-here" ) response = client.chat.completions.create( model="MODEL-FROM-LIST", messages=[ {"role": "user", "content": "Hello!"} ] ) print(response.choices[0].message.content) ``` ``` -------------------------------- ### Python: LLM Inference with Streaming Source: https://github.com/nahcrof-code/crofai/blob/main/README.md This example demonstrates how to perform LLM inference with streaming enabled. This is useful for receiving responses in real-time. Replace 'MODEL-FROM-LIST' with a valid model ID. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="api-key-here" ) response = client.chat.completions.create( model="MODEL-FROM-LIST", messages=[ {"role": "user", "content": "Howdy there! How are you?"} ], stream=True # Enable streaming ) for chunk in response: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() ``` -------------------------------- ### API Response Structure: /models Source: https://github.com/nahcrof-code/crofai/blob/main/README.md This is an example of the JSON structure returned when querying the /v1/models endpoint. It provides details about each available model, including its ID, context length, pricing, and speed. ```json { "context_length": 163840, "created": 1755799640, "id": "deepseek-v3.2", "max_completion_tokens": 163840, "name": "DeepSeek: DeepSeek V3.2", "pricing": { "completion": "0.00000038", // $0.38/m output "prompt": "0.00000028" // $0.28/m input }, "quantization": "Q4_0", "speed": 50 // rough estimate } ``` -------------------------------- ### Python: Basic LLM Inference Source: https://github.com/nahcrof-code/crofai/blob/main/README.md Use this snippet for standard LLM inference without streaming. Ensure you have the OpenAI library installed and replace 'MODEL-FROM-LIST' with a valid model ID. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="api-key-here" ) response = client.chat.completions.create( model="MODEL-FROM-LIST", messages=[ {"role": "user", "content": "Hello!"} ] ) print(response.choices[0].message.content) ``` -------------------------------- ### Interact with Anthropic API using Python SDK Source: https://context7.com/nahcrof-code/crofai/llms.txt This Python code demonstrates how to use the official `anthropic` SDK with CrofAI's Anthropic-compatible endpoint. Update `base_url` and `api_key` for your specific setup. ```python import anthropic client = anthropic.Anthropic( base_url="https://anthropic.nahcrof.com", api_key="your-crof-api-key" ) message = client.messages.create( model="claude-3-5-sonnet-20241022", # use a model ID available on CrofAI max_tokens=256, messages=[ {"role": "user", "content": "What is the capital of France?"} ] ) print(message.content[0].text) # Expected output: Paris. ``` -------------------------------- ### Python: Vision Model Inference Source: https://github.com/nahcrof-code/crofai/blob/main/README.md This snippet demonstrates how to use vision models for image analysis. It sends a text prompt along with an image URL to the model. Vision models are identified with a '(vision)' tag in the pricing page. Replace 'kimi-k2.5' if a different vision model is preferred. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="api-key-here" ) response = client.chat.completions.create( model="kimi-k2.5", # vision models are labeled in the pricing page with the (vision) tag messages=[ { "role": "user", "content": [ {"type": "text", "text": "What is in this image?"}, { "type": "image_url", "image_url": { "url": "https://files.nahcrof.com/file/crofai-black.png", }, }, ], } ], stream=True ) for chunk in response: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() ``` -------------------------------- ### Chat Completions (Streaming) with OpenAI SDK Source: https://context7.com/nahcrof-code/crofai/llms.txt Enable token-by-token streaming by setting `stream=True`. Iterate over the response chunks and print them as they arrive, suitable for real-time UIs or CLI tools. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) response = client.chat.completions.create( model="deepseek-v3.2", messages=[ {"role": "user", "content": "Write a short poem about the ocean."} ], stream=True, max_tokens=200, temperature=0.9 ) for chunk in response: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() # Expected output: A short poem printed incrementally, token by token. ``` -------------------------------- ### List Available Models Source: https://context7.com/nahcrof-code/crofai/llms.txt This section details how to retrieve a comprehensive list of all available models through the `/v1/models` endpoint. It includes information on context window size, pricing, quantization, and estimated throughput speed for each model. ```APIDOC ## List Available Models (`GET /v1/models`) Retrieve the full list of available models, including context window size, pricing, quantization, and estimated throughput speed. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) models = client.models.list() for model in models.data: print(f"ID: {model.id}") # Access extra fields via the raw dict if needed raw = model.model_dump() if hasattr(model, "model_dump") else vars(model) print(f" Name: {raw.get('name', 'N/A')}") print(f" Context length: {raw.get('context_length', 'N/A')}") print(f" Max output tokens: {raw.get('max_completion_tokens', 'N/A')}") print(f" Quantization: {raw.get('quantization', 'N/A')}") pricing = raw.get("pricing", {}) print(f" Prompt price: ${float(pricing.get('prompt', 0)) * 1_000_000:.4f}/M tokens") print(f" Completion price: ${float(pricing.get('completion', 0)) * 1_000_000:.4f}/M tokens") print(f" Speed (est.): {raw.get('speed', 'N/A')} tok/s") print() # Example output for one model: # ID: deepseek-v3.2 # Name: DeepSeek: DeepSeek V3.2 ``` ``` -------------------------------- ### Chat Completions (Streaming) Source: https://context7.com/nahcrof-code/crofai/llms.txt Enable token-by-token streaming by passing `stream=True`. Each chunk is iterated and printed as it arrives, suitable for real-time UIs or CLI tools. ```APIDOC ## Chat Completions (Streaming) ### Description Enable token-by-token streaming by passing `stream=True`. Each chunk is iterated and printed as it arrives, suitable for real-time UIs or CLI tools. ### Method POST ### Endpoint `/v1/chat/completions` ### Parameters #### Request Body - **model** (string) - Required - The model to use for completion. - **messages** (array) - Required - A list of messages comprising the conversation. - **stream** (boolean) - Required - Set to `True` to enable streaming. - **max_tokens** (integer) - Optional - The maximum number of tokens to generate. - **temperature** (number) - Optional - Controls randomness. Lower values make output more focused and deterministic. - **top_p** (number) - Optional - Controls diversity via nucleus sampling. - **stop** (string or array) - Optional - Sequences where the API will stop generating further tokens. - **seed** (integer) - Optional - A seed for reproducible results. - **tools** (array) - Optional - A list of tools the model may call. ### Request Example ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) response = client.chat.completions.create( model="deepseek-v3.2", messages=[ {"role": "user", "content": "Write a short poem about the ocean."} ], stream=True, max_tokens=200, temperature=0.9 ) for chunk in response: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() ``` ### Response #### Success Response (200) - **choices** (array) - A list of completion choices. - **delta** (object) - The change in the message content. - **content** (string) - The content of the message chunk. #### Response Example ```json { "id": "chatcmpl-xxxxxxxxxxxxxxxxxxxxxxxxx", "object": "chat.completion.chunk", "created": 1700000000, "model": "deepseek-v3.2", "choices": [ { "index": 0, "delta": { "role": "assistant", "content": "The ocean whispers secrets deep," }, "logprobs": null, "finish_reason": null } ] } ``` ``` -------------------------------- ### Vision / Multimodal Input Source: https://context7.com/nahcrof-code/crofai/llms.txt This section explains how to use vision-capable models by passing a list of content blocks that include both text and image URLs. It shows how to structure the `content` parameter for multimodal inputs. ```APIDOC ## Vision / Multimodal Input Pass a list of content blocks containing both text and `image_url` entries to query vision-capable models. Vision models are identified with a `(vision)` tag on the CrofAI pricing page. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) response = client.chat.completions.create( model="kimi-k2.5", # vision-capable model messages=[ { "role": "user", "content": [ {"type": "text", "text": "Describe this image in detail."}, { "type": "image_url", "image_url": { "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png" }, }, ], } ], stream=True, max_tokens=512 ) for chunk in response: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() # Expected output: A detailed textual description of the provided image. ``` ``` -------------------------------- ### Python Tool/Function Calling with CrofAI Source: https://context7.com/nahcrof-code/crofai/llms.txt Demonstrates how to define tools as JSON schemas and handle tool calls from the model. The model emits tool_calls, which your code executes and feeds results back to continue the conversation. ```python from openai import OpenAI import json client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) tools = [ { "type": "function", "function": { "name": "get_weather", "description": "Get the current weather for a given city.", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "The name of the city, e.g. 'London'", } }, "required": ["city"], "additionalProperties": False, }, "strict": True, }, } ] def get_weather(city: str) -> str: # Stub — replace with a real weather API call return json.dumps({"city": city, "temperature": "18°C", "condition": "Cloudy"}) messages = [{"role": "user", "content": "What's the weather like in Tokyo?"}] stream = client.chat.completions.create( model="deepseek-v3.2", messages=messages, tools=tools, stream=True ) tool_name = None tool_args = "" for chunk in stream: delta = chunk.choices[0].delta if delta.content: print(delta.content, end="", flush=True) if delta.tool_calls: for tc in delta.tool_calls: if tc.function.name: tool_name = tc.function.name if tc.function.arguments: tool_args += tc.function.arguments if tool_name: args = json.loads(tool_args) result = get_weather(**args) print(f"\n[Tool '{tool_name}' called with args {args}]") print(f"[Tool result: {result}]") # Continue the conversation with the tool result messages.append({"role": "assistant", "tool_calls": [{"id": "call_1", "type": "function", "function": {"name": tool_name, "arguments": tool_args}}]}) messages.append({"role": "tool", "tool_call_id": "call_1", "content": result}) final = client.chat.completions.create( model="deepseek-v3.2", messages=messages ) print(final.choices[0].message.content) # Expected output: # [Tool 'get_weather' called with args {'city': 'Tokyo'}] # [Tool result: {"city": "Tokyo", "temperature": "18°C", "condition": "Cloudy"}] # The weather in Tokyo is currently 18°C and cloudy. ``` -------------------------------- ### Python: Reasoning Model Inference with Streaming Source: https://github.com/nahcrof-code/crofai/blob/main/README.md This snippet shows how to use reasoning models with streaming. It specifically captures and prints `reasoning_content` if available, falling back to `content`. Replace 'MODEL-FROM-LIST' with a valid model ID. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="api-key-here" ) response = client.chat.completions.create( model="MODEL-FROM-LIST", messages=[ {"role": "user", "content": "Howdy there! How are you?"} ], stream=True # Enable streaming ) for chunk in response: try: if chunk.choices and chunk.choices[0].delta.reasoning_content: print(chunk.choices[0].delta.reasoning_content, end="", flush=True) except AttributeError: pass if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() ``` -------------------------------- ### List Models with Curl Source: https://context7.com/nahcrof-code/crofai/llms.txt Use this curl command to list available models via the CrofAI API. Ensure you replace 'your-crof-api-key' with your actual API key. ```bash curl https://crof.ai/v1/models \ -H "Authorization: Bearer your-crof-api-key" \ | python3 -m json.tool ``` -------------------------------- ### Tool / Function Calling Source: https://context7.com/nahcrof-code/crofai/llms.txt This section demonstrates how to define tools using JSON schemas and integrate them with the CrofAI API for function calling. It shows how the model can emit `tool_calls` and how to execute these functions and feed the results back into the conversation. ```APIDOC ## Tool / Function Calling Define tools as JSON schemas and pass them in the `tools` parameter. The model will emit `tool_calls` deltas when it decides to invoke a function; your code handles execution and can feed results back. ```python from openai import OpenAI import json client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) tools = [ { "type": "function", "function": { "name": "get_weather", "description": "Get the current weather for a given city.", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "The name of the city, e.g. 'London'", } }, "required": ["city"], "additionalProperties": False, }, "strict": True, }, } ] def get_weather(city: str) -> str: # Stub — replace with a real weather API call return json.dumps({"city": city, "temperature": "18°C", "condition": "Cloudy"}) messages = [{"role": "user", "content": "What's the weather like in Tokyo?"}] stream = client.chat.completions.create( model="deepseek-v3.2", messages=messages, tools=tools, stream=True ) tool_name = None tool_args = "" for chunk in stream: delta = chunk.choices[0].delta if delta.content: print(delta.content, end="", flush=True) if delta.tool_calls: for tc in delta.tool_calls: if tc.function.name: tool_name = tc.function.name if tc.function.arguments: tool_args += tc.function.arguments if tool_name: args = json.loads(tool_args) result = get_weather(**args) print(f"\n[Tool '{tool_name}' called with args {args}]") print(f"[Tool result: {result}]") # Continue the conversation with the tool result messages.append({"role": "assistant", "tool_calls": [{"id": "call_1", "type": "function", "function": {"name": tool_name, "arguments": tool_args}}]}) messages.append({"role": "tool", "tool_call_id": "call_1", "content": result}) final = client.chat.completions.create( model="deepseek-v3.2", messages=messages ) print(final.choices[0].message.content) # Expected output: # [Tool 'get_weather' called with args {'city': 'Tokyo'}] # [Tool result: {"city": "Tokyo", "temperature": "18°C", "condition": "Cloudy"}] # The weather in Tokyo is currently 18°C and cloudy. ``` ``` -------------------------------- ### Python Multimodal Input with CrofAI Source: https://context7.com/nahcrof-code/crofai/llms.txt Shows how to send both text and image URLs in a single request to vision-capable models. Ensure the model used is identified as vision-capable. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) response = client.chat.completions.create( model="kimi-k2.5", # vision-capable model messages=[ { "role": "user", "content": [ {"type": "text", "text": "Describe this image in detail."}, { "type": "image_url", "image_url": { "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png" }, }, ], } ], stream=True, max_tokens=512 ) for chunk in response: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() # Expected output: A detailed textual description of the provided image. ``` -------------------------------- ### Chat Completions (No Streaming) with OpenAI SDK Source: https://context7.com/nahcrof-code/crofai/llms.txt Send a single user message and receive a complete response synchronously. Configure the OpenAI SDK by setting the `base_url` to the CrofAI endpoint and providing your API key. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) response = client.chat.completions.create( model="deepseek-v3.2", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain quantum entanglement in one sentence."} ], max_tokens=256, temperature=0.7 ) print(response.choices[0].message.content) # Expected output: A one-sentence explanation of quantum entanglement. ``` -------------------------------- ### Reasoning Model Output (Streaming) with OpenAI SDK Source: https://context7.com/nahcrof-code/crofai/llms.txt Capture the model's internal chain-of-thought (`reasoning_content`) before the final answer when using reasoning-capable models. This field is available on the delta during streaming. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) response = client.chat.completions.create( model="deepseek-r1", # reasoning-capable model messages=[ {"role": "user", "content": "How many prime numbers are less than 50?"} ], stream=True ) print("=== Reasoning ===") for chunk in response: try: if chunk.choices and chunk.choices[0].delta.reasoning_content: print(chunk.choices[0].delta.reasoning_content, end="", flush=True) except AttributeError: pass if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() # Expected output: Internal reasoning steps followed by the final answer. ``` -------------------------------- ### Python List Available Models with CrofAI Source: https://context7.com/nahcrof-code/crofai/llms.txt Retrieves a list of all available models from the CrofAI API, including details like context length, pricing, and estimated throughput. Extra fields can be accessed via the raw dictionary. ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) models = client.models.list() for model in models.data: print(f"ID: {model.id}") # Access extra fields via the raw dict if needed raw = model.model_dump() if hasattr(model, "model_dump") else vars(model) print(f" Name: {raw.get('name', 'N/A')}") print(f" Context length: {raw.get('context_length', 'N/A')}") print(f" Max output tokens: {raw.get('max_completion_tokens', 'N/A')}") print(f" Quantization: {raw.get('quantization', 'N/A')}") pricing = raw.get("pricing", {}) print(f" Prompt price: ${float(pricing.get('prompt', 0)) * 1_000_000:.4f}/M tokens") print(f" Completion price: ${float(pricing.get('completion', 0)) * 1_000_000:.4f}/M tokens") print(f" Speed (est.): {raw.get('speed', 'N/A')} tok/s") print() # Example output for one model: # ID: deepseek-v3.2 # Name: DeepSeek: DeepSeek V3.2 ``` -------------------------------- ### List Available Models (OpenAI Compatible) Source: https://context7.com/nahcrof-code/crofai/llms.txt Retrieve a list of all models available through the CrofAI platform using the OpenAI compatible endpoint. ```APIDOC ## GET /v1/models ### Description Retrieves a list of available models. ### Method GET ### Endpoint /v1/models ### Request Example ```bash curl https://crof.ai/v1/models \ -H "Authorization: Bearer your-crof-api-key" \ | python3 -m json.tool ``` ### Response #### Success Response (200) - **data** (array) - List of available models. - **object** (string) - The type of object returned, should be "list". - **id** (string) - The unique identifier for the model. - **owned_by** (string) - The entity that owns the model. - **created_at** (integer) - Timestamp of model creation. - **permission** (array) - Permissions associated with the model. ``` -------------------------------- ### Reasoning Model Output (Streaming) Source: https://context7.com/nahcrof-code/crofai/llms.txt Some models expose a `reasoning_content` field on the delta alongside the final `content`. This allows you to capture the model's internal chain-of-thought before the final answer. ```APIDOC ## Reasoning Model Output (Streaming) ### Description Some models expose a `reasoning_content` field on the delta alongside the final `content`. This allows you to capture the model's internal chain-of-thought before the final answer. ### Method POST ### Endpoint `/v1/chat/completions` ### Parameters #### Request Body - **model** (string) - Required - The model to use for completion (e.g., `deepseek-r1`). - **messages** (array) - Required - A list of messages comprising the conversation. - **stream** (boolean) - Required - Set to `True` to enable streaming. ### Request Example ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) response = client.chat.completions.create( model="deepseek-r1", # reasoning-capable model messages=[ {"role": "user", "content": "How many prime numbers are less than 50?"} ], stream=True ) print("=== Reasoning ===") for chunk in response: try: if chunk.choices and chunk.choices[0].delta.reasoning_content: print(chunk.choices[0].delta.reasoning_content, end="", flush=True) except AttributeError: pass if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) print() ``` ### Response #### Success Response (200) - **choices** (array) - A list of completion choices. - **delta** (object) - The change in the message content. - **reasoning_content** (string) - The model's internal reasoning steps. - **content** (string) - The final content of the message chunk. #### Response Example ```json { "id": "chatcmpl-xxxxxxxxxxxxxxxxxxxxxxxxx", "object": "chat.completion.chunk", "created": 1700000000, "model": "deepseek-r1", "choices": [ { "index": 0, "delta": { "reasoning_content": "Prime numbers less than 50 are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47.", "content": "There are 15 prime numbers less than 50." }, "logprobs": null, "finish_reason": "stop" } ] } ``` ``` -------------------------------- ### /models API Source: https://github.com/nahcrof-code/crofai/blob/main/README.md Information about the /v1/models API endpoint, which returns a list of available models with their details. ```APIDOC ## /models API ### Description When visiting `/v1/models` you will receive a standard JSON list containing each model. Each model should look as follows ### Response Example ```json { "context_length": 163840, "created": 1755799640, "id": "deepseek-v3.2", "max_completion_tokens": 163840, "name": "DeepSeek: DeepSeek V3.2", "pricing": { "completion": "0.00000038", // $0.38/m output "prompt": "0.00000028" // $0.28/m input }, "quantization": "Q4_0", "speed": 50 // rough estimate } ``` ``` -------------------------------- ### Chat Completions (No Streaming) Source: https://context7.com/nahcrof-code/crofai/llms.txt Send a single user message and receive a complete response synchronously. Configure the OpenAI SDK's base_url to the CrofAI endpoint and provide your API key. ```APIDOC ## Chat Completions (No Streaming) ### Description Send a single user message and receive a complete response synchronously. The client is configured by pointing the OpenAI SDK's `base_url` at the CrofAI endpoint and supplying your CrofAI API key. ### Method POST ### Endpoint `/v1/chat/completions` ### Parameters #### Request Body - **model** (string) - Required - The model to use for completion. - **messages** (array) - Required - A list of messages comprising the conversation. - **max_tokens** (integer) - Optional - The maximum number of tokens to generate. - **temperature** (number) - Optional - Controls randomness. Lower values make output more focused and deterministic. - **top_p** (number) - Optional - Controls diversity via nucleus sampling. - **stop** (string or array) - Optional - Sequences where the API will stop generating further tokens. - **seed** (integer) - Optional - A seed for reproducible results. - **tools** (array) - Optional - A list of tools the model may call. ### Request Example ```python from openai import OpenAI client = OpenAI( base_url="https://crof.ai/v1", api_key="your-crof-api-key" ) response = client.chat.completions.create( model="deepseek-v3.2", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain quantum entanglement in one sentence."} ], max_tokens=256, temperature=0.7 ) print(response.choices[0].message.content) ``` ### Response #### Success Response (200) - **choices** (array) - A list of completion choices. - **message** (object) - The generated message. - **content** (string) - The content of the message. #### Response Example ```json { "id": "chatcmpl-xxxxxxxxxxxxxxxxxxxxxxxxx", "object": "chat.completion", "created": 1700000000, "model": "deepseek-v3.2", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Quantum entanglement is a phenomenon where two or more quantum particles become linked in such a way that they share the same fate, regardless of the distance separating them." }, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 30, "completion_tokens": 35, "total_tokens": 65 } } ``` ``` -------------------------------- ### Anthropic Messages API (Python SDK) Source: https://context7.com/nahcrof-code/crofai/llms.txt Interact with the Anthropic-compatible endpoint using the official `anthropic` Python SDK. Simply configure the `base_url` and `api_key`. ```APIDOC ## Anthropic Messages API ### Description Uses the Anthropic Messages API compatible endpoint with the `anthropic` Python SDK. ### Method POST (via SDK) ### Endpoint `base_url="https://anthropic.nahcrof.com"` ### Parameters (SDK) - **model** (string) - Required - The ID of the model to use. - **max_tokens** (integer) - Required - The maximum number of tokens to generate. - **messages** (array) - Required - The conversation history. ### Request Example (Python SDK) ```python import anthropic client = anthropic.Anthropic( base_url="https://anthropic.nahcrof.com", api_key="your-crof-api-key" ) message = client.messages.create( model="claude-3-5-sonnet-20241022", # use a model ID available on CrofAI max_tokens=256, messages=[ {"role": "user", "content": "What is the capital of France?"} ] ) print(message.content[0].text) ``` ### Response Example (Python SDK) ``` Paris. ``` ``` -------------------------------- ### Interact with Anthropic API using Curl Source: https://context7.com/nahcrof-code/crofai/llms.txt This curl command shows how to interact with CrofAI's Anthropic-compatible endpoint for message creation. Remember to use your specific API key and desired model. ```bash curl https://anthropic.nahcrof.com/v1/messages \ -H "x-api-key: your-crof-api-key" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{ "model": "claude-3-5-sonnet-20241022", "max_tokens": 256, "messages": [{"role": "user", "content": "What is the capital of France?"}] }' ``` -------------------------------- ### Anthropic Messages API (curl) Source: https://context7.com/nahcrof-code/crofai/llms.txt Interact with the Anthropic-compatible endpoint using `curl`. ```APIDOC ## Anthropic Messages API (curl) ### Description Uses `curl` to interact with the Anthropic-compatible endpoint. ### Method POST ### Endpoint https://anthropic.nahcrof.com/v1/messages ### Headers - **Authorization** (string) - Required - Your CrofAI API key, prefixed with `Bearer `. - **anthropic-version** (string) - Required - The Anthropic API version. - **content-type** (string) - Required - Set to `application/json`. ### Request Body - **model** (string) - Required - The ID of the model to use. - **max_tokens** (integer) - Required - The maximum number of tokens to generate. - **messages** (array) - Required - The conversation history. ### Request Example ```bash curl https://anthropic.nahcrof.com/v1/messages \ -H "x-api-key: your-crof-api-key" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{ "model": "claude-3-5-sonnet-20241022", "max_tokens": 256, "messages": [{"role": "user", "content": "What is the capital of France?"}] }' ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.