Producing a new work that happens to be similar to, or even word for word identical to an existing work, if you truly created it yourself from scratch without taking anything from the existing work, would not be copying.
As a practical matter, unless you had extraordinary proof that you really had never read Harry Potter books, watched the movies, read the plot summaries on Wikipedia, attended a party shortly after one of the books came out where everyone was talking about it, you would lose in a copyright infringement lawsuit. If you work is very similar to Harry Potter and you had access to Harry Potter, that's sufficient for the plaintiff to make their case, switching the burden to you to prove that you did not copy it.
There is no plot in an API, no main characters, etc. It communicates matters of technical nature, and there aren't five different way of writing 'sqrt()' or whatever. It is more appropriately compares to architechtural blueprints and other technical documents.